Mininal pattern matching regular expression?

A simple way around your problem is to match: (a. *b) With the first being greedy, it matches as much as it can. Then you get a captured group with the match you really need, ( $1 ).

Note that this assumes you're matching the last occurrence of the pattern. You may want (a. *?

B) if you have multiple be s near the end of the string, and you want the first one after the last a.

A simple way around your problem is to match: . *(a. *b) With the first .

* being greedy, it matches as much as it can. Then you get a captured group with the match you really need, ($1). Note that this assumes you're matching the last occurrence of the pattern.

You may want . *(a. *?

B) if you have multiple bs near the end of the string, and you want the first one after the last a.

– AgA Mar 23 at 6:52 2 @user - not that I'm aware of. . Net can match right-to-left, or you can always reverse the string and match b.

*?a. You can also try something like a((?! A).

)*b (or a^a*b), but it can get messy with a complex pattern - I assume you need a little more than a and b... – Kobi Mar 23 at 6:54 this is the specific pattern for this. – ysth Mar 23 at 7:35 Kobi you are genius. – AgA Mar 230 at 12:55.

One of: /a^a*b/ /a^ab*b/ /a(?:(?! A). )*b/ /a(?:(?!

A|b). )*b/ The last two are provided in case a and be are actually more complex patterns.

The pattern matching in Perl is Left Most, Longest* by default. Using? , *?

, or +? Will change that portion to Left Most, Shortest, but Left Most still takes precedence. There is a way to get Perl to match Right Most, which might get you your desired effect, but it will also confuse the hell out of the next person to read your code, so use it with care.

The basic idea is to reverse everything related to the pattern match, so right becomes left. My $subject = 'ajjjjjjjjjaab'; my $rev_sub = reverse $subject; # reverse the string being matched. My $result; if ($rev_sub =~ /(b.

*? A)/) { # reverse the pattern to match. $result = reverse $1; # reverse the results of the match.

} print $result; The solutions provided by ikegami and Kobi both find similar results for your example. Depending on your real patterns and strings you might find very different performance for each method. Always Benchmark based off your real needs.

*Longest only for the immediate token being matched, excluding alternations which are tried in order left to right, etc.

2 Note: That approach fails for a...a...b...b. – ikegami Mar 23 at 17:22.

Ok, but then use just /ab/ for matching and you go it. Or /a{1}b/. Or?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions