I have the following regex: a?\W*?b and I have a string ,.! ,bWhen searching for a match, I get ,.! ,b, but not just bas I expect. Why is this? How to change regex to get what I need?Thanks for the help.
a?\W*?b
,.! ,b
b
The len quantifier does not help here what you want. Let's see what happens.
The regex engine starts at the beginning of the line. First tries to match a. He cannot, but this is not a problem, since ait is not mandatory.
a
\W*?, regex , .
\W*?
b. , , \W*?. b (- ). . , , , b. - .
,
, - , . : ?
, :
b , a , a b,
b|a\W*b
, , , .
, , , , .
, : (a\W*)?b
(a\W*)?b
, , .
:
regexp b ( ).
',.!, db ' b.
a? : " , a" - , ,
a?
\W* : " ", , ,
\W*
b " b", . .
, , - .
, a? , b , ,.! ,b, lookbehind (?=\W*?)b.
(?=\W*?)b
b, , " ", ( )
say a b , a,.! ,b, : (a?)\W*?(b), a, , 2 b
a,.! ,b
(a?)\W*?(b)
. , , . , , . ,
Regex.Match("foo bar", @"\w+ (?:b|bar)")
... foo b, , , . ( , Perle- , .NET, , awk egrep, . , - , - , .)
foo b
awk
egrep
Source: https://habr.com/ru/post/1750974/More articles:Is there a way to "extend" the #define directive? - c ++Is there a way to connect Wi-Fi using PPPoE on Android? - androidhow to get selector from jquery object? - jqueryR-time object with two time dimensions - datetimeChange CSS dynamically with GWT - cssThe serial number of the device displayed on adb devices - androidListen to MIDI on the client over the Internet? - .netWhat is the structure of the MIDI file? - language-agnosticHow expensive are callbacks? - cSorting arrays in Java using flag sorting - javaAll Articles