I've not been able to figure this simple regex problem. I need to match strings in one of the two formats below (after reading from a file):
"/moreIters 10"
"/bootMe any text here"
/fewIter
If the string begins with a quote, I need all data enclosed within the quotes, else the entire string that begins with /
To begin with, I wrote the following simplistic regex:
which means match zero or 1 double quote, followed by / followed by any number of characters followed by an optional double quote. However, this doesn't work because .* matches the quotes as well, and I get the following:$str =~ m,"?(/.*)"?,
The above works for strings such as /justThis:my $str = qq( "/extend 100" ); $str =~ m,"?(/.*)"?,; if (defined $1) { print "matched=$1\n"; } $perl regex.pl matched=/extend 100"
How can I refine this regex to get the desired result?my $str = qq(/extendMe ); $str =~ m,"?(/.*)"?,; if (defined $1) { print "matched=$1\n"; } $perl regex.pl matched=/extendMe
Thanks!
In reply to dumb regex question by linuxfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |