How can I match everything that is after the last occurrence of some char in a perl regular expression?
my($substr) = $string =~ /.*x(.*)/;
From perldoc perlre:
By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match.
That's why .*x
will match up to the last occurence of x
.
The simplest way would be to use /([^x]*)$/
the first answer is a good one, but when talking about "something that does not contain"... i like to use the regex that "matches" it
my($substr) = $string =~ /.*x([^x]*)$/;
very usefull in some case