regex: negative lookbehind in negation character class? (.NET flavour) -
What I'm trying to do: is a specific, unexpected character ( \
escape)
Input: [\ [x \]] \] \ [[\] [y]]
output when looking for bracket around y: around X [\ [x \]] \ [\ [y]]
output: \ [x \] \] \ [[\ [y] \ in search of bracket \ ]]
In short, remove only the set of brackets around the specific character.
I tried it (for): Regex.Replace (Input, @ "(? & Lt;! \\) \ [(*. (? , but this is not the last
]
unchanged
(before X). I thought I could change .
[
and ]
to exclude Wildcard with a negative character for class, but I need to reject them Unscacked of these editions, and when I I try to include a negative attitude such as (? & Lt;! \\)
edit:
To clarify To explain the content,
The divided square brackets can be anything (except another unchanging class bracket), as long as they contain unsecured characters of interest ( y
. All contents of the bracket should be.
Lookbehind wrong for this job Pakrn instead try it:
Regex r = new Regex (@ "\ [((? & Gt; (?: [^ Y \ [\] \\] | \\.) *) Y (?> (:: [^ \ [\] \\] | \\) *)) \] "); String s1 = "[\ [x \]] \] \ [[\ \ y]]"; Console.WriteLine (S1); Console.light line (R. Change (s1, @ "% $ 1% "Console.WriteLine (); String s2 = @ [" [\ [x]] \] \ [[1234 (\ [abcycba \] \ y \ y]] "; Console.WriteLine (s2); Console Change the Light Line (R2, @ "% $ 1%"));
Result:
[\ [x \] ] \ [\ [X \]] \] \ [% \ [y \]%
[\ [x \]] \] \ [[1234 (\ abcycba \] \ y \ y)]
[\ [x \]] \] \ [1234] (\ [Abcycba \] \ y \ y)%
(Instead of replacing it, replace it with %
instead of bracket
(?: \\ | [^ Y \ [\] \\]) *
zero or more (1) backslash behind any character, or (2) Whatever 'Y' is not a square bracket or backslash, if the next letter is a 'Y', then it is consumed and it is consumed and (?: \\. | [^ \ [\ ] \\]) *
matches any remaining letter in the next remaining letter. Include both cells in the denoted character squared (with backslash) to ensure that you only match the simplest set of unrecognized brackets.
It is also important that you -, (? & Gt; ...)
; This prevents back-locking which we know will be useless, and which can cause serious performance problems when the rijks are used on the wires in which there is no matching.
An alternative approach is very simple to consume the letters between 'Y' and then brackets; (? & Gt; (?: \\. | [[\ [\] \\ ]) *)
. The problem is that you are now making two passes on the string, and it can be difficult to make sure the letterhead does not look forward to too far , or not too far. By doing all the work in one pass, it is known that where you are at each stage of the matching process.
Comments
Post a Comment