P
Peder Ydalus
Hi!
What is the purpose of the following regex:
$f =~ s#/\*.*?\*/##g;
- Peder -
What is the purpose of the following regex:
$f =~ s#/\*.*?\*/##g;
- Peder -
Peder Ydalus said:What is the purpose of the following regex:
$f =~ s#/\*.*?\*/##g;
Peder said:What is the purpose of the following regex:
$f =~ s#/\*.*?\*/##g;
Deleting the contents of a C-style comment from $f. Probably. I
can't be arsed to come up with legal comments that would fail it, but
there probably are some. At the very least, this value of $f won't
work:
$f = "A /* multi-line\ncomment */";
I don't understand what the .*? bit is supposed to do... '.*' in this
context says, "grab every non-newline character following the original
literal * character", but then following it with ? either means
whoever wrote it didn't understand regexes, or got distracted in the
middle of editing one, or something really subtle is going on.
Martien Verbruggen said:The question mark makes the preceding * non-greedy.
Given how broken
the original regex is to match C-style comments, the person who
created it probably just put it in to "fix" one of the bits that this
thing didn't "correctly" match.
Peder said:Hi!
What is the purpose of the following regex:
$f =~ s#/\*.*?\*/##g;
- Peder -
Peder said:Thanks a lot!
This was far more than I could ever have hoped for.
- Peder -
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.