Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
(?:(A[^B]+B).*?)+N
/
gm
Input 1
1
New
explaining using lower case so this text doesn't match: recapitalize to test m-n are the outer borders, a-b inner borders M AxB AyB AzB N in VERY simple cases like this, this will work a([^b])b webgrabplus will find 3 matches with 1 group each, and regard it as 3 shows. however this quickly fails in more complicated scenarios, where something like the following is better: (?:(a[^b]+b).*?)+n we're looking for 1 or more outer groups followed by n that outer group is made of an inner group followed by anything (minimally) until the end of the outer group the inner group is made of anything between a and b wg+ will find one outer-group match, with one inner-group match at the END. then it will work backwards within the outer group looking for other inner-group matches, unlike a regex displayer like this website, which only highlights capturing the last item. the outer noncapturing group is necessary to allow matching additional ab pairs, because any pairs that come before the last still have to be valid matches overall, including the stuff that comes after them, like any commas or the matches that have already been found at the end. easy mistake: capturing the whole group with no outer group M(.*)N wg+ will grab the whole block thinking it's one program, your following regexes will be garbage in garbage out easy mistake: no minimal matching for the inner group so that the pattern matches the first item in the list (?:(a[^b]+b).*)+n wg+ will only grab the 1st item a more complicated example: https://regex101.com/r/1hL3Cz/
Extraction
explaining using lower case so this text doesn't match: recapitalize to test m-n are the outer borders, a-b inner borders M AxB AyB AzB N in VERY simple cases like this, this will work a([^b])b webgrabplus will find 3 matches with 1 group each, and regard it as 3 shows. however this quickly fails in more complicated scenarios, where something like the following is better: (?:(a[^b]+b).*?)+n we're looking for 1 or more outer groups followed by n that outer group is made of an inner group followed by anything (minimally) until the end of the outer group the inner group is made of anything between a and b wg+ will find one outer-group match, with one inner-group match at the END. then it will work backwards within the outer group looking for other inner-group matches, unlike a regex displayer like this website, which only highlights capturing the last item. the outer noncapturing group is necessary to allow matching additional ab pairs, because any pairs that come before the last still have to be valid matches overall, including the stuff that comes after them, like any commas or the matches that have already been found at the end. easy mistake: capturing the whole group with no outer group M(.*)N wg+ will grab the whole block thinking it's one program, your following regexes will be garbage in garbage out easy mistake: no minimal matching for the inner group so that the pattern matches the first item in the list (?:(a[^b]+b).*)+n wg+ will only grab the 1st item a more complicated example: https://regex101.com/r/1hL3Cz/