I have a string like fcsNotificationZK44_0376300009215000019_4158794.xml
and a pattern (fcs.*)_
the target is to get fcsNotificationZK44
but standart C# Regex
matched at fcsNotificationZK44_0376300009215000019
becouse it is greedy. In javascript I can use /U
modifier to turn on ungreedy mode but how to solve it in C# Regex
? Thanks.
A regular expression is a sequence of characters used to match a pattern to a string. The expression can be used for searching text and validating input. Remember, a regular expression is not the property of a particular language. POSIX is a well-known library used for regular expressions in C.
Regex recognizes common escape sequences such as \n for newline, \t for tab, \r for carriage-return, \nnn for a up to 3-digit octal number, \xhh for a two-digit hex code, \uhhhh for a 4-digit Unicode, \uhhhhhhhh for a 8-digit Unicode.
\\. matches the literal character . . the first backslash is interpreted as an escape character by the Emacs string reader, which combined with the second backslash, inserts a literal backslash character into the string being read. the regular expression engine receives the string \. html?\ ' .
Greedy: As Many As Possible (longest match) By default, a quantifier tells the engine to match as many instances of its quantified token or subpattern as possible. This behavior is called greedy. For instance, take the + quantifier.
Use *?
to make the *
non-greedy.
Reference: http://www.regular-expressions.info/repeat.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With