Question

while ($aaa =~ m/= "(\D.*?)"/g) 

I figured that it matches while $aaa is like anything = "something" it returns something (without the quotation mark).

But what does this piece of code mean?

m/= "(\D.*?)"/
Was it helpful?

Solution

You seem to have figured out most of it. The =, , and " all literally match those characters. The () capture a part of the matched string and make it available as $1. The part inside the parenthesis matches a non-digit character (\D), followed by zero or more (*?) non-newline characters (.) until the ". * would also match zero or more times, but prefers to match more characters so would end up matching until the last " in the string instead of the next one, as *? does.

All of this is documented in perlre.

OTHER TIPS

The equals sign and quotation mark are taken literally, \D means any non-digit, .*? followed or not by zero or more characters, of any kind.

From left to right:

m/= "(\D.*?)"/g

match operator, 
start regex: 
  equals sign, whitespace, double quotation mark, 
  start group: 
    one non-digit character, zero or more characters, 
  end group, 
  double quotation mark, 
end regex
match globally
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top