For some reason the ([^ ]+) section stops at the forward slash, even though it's clearly not a space.Actually, it's not stopping at the forward slash. The regex tries to match as much as possible, so it does match up to the space. However, that causes the rest of the regex to fail, so the regex engine keeps backtracking and retrying the regex. In this case, backtracking to the / allows the regex to match.
What happened was, you forgot a quantifier. Try the following regex (cleaned up):
Here's the cleaned up version of the regex:$data =~ /[^\d]+([^ ]+)[^\d]+(\d+)(.*?)$/;
You'll notice that the [^\d] between the first and second set of parens now has a + after it.$data =~ /\D+(\S+)\D+(\d+)(.*)$/;
Breaking out the regex for those who prefer it:
$data =~ / \D+ # One or more non-digits ( # Capture to $1 \S+ # non-spaces ) \D+ # One or more non-digits ( # Capture to $2 \d+ # one or more digits ) ( # Capture to $3 .* # rest of string )$ # Anchor above to end of string /x;
Cheers,
Ovid
Update: Darn it! Guildenstern beat me to it!
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
In reply to (Ovid) Re: Matching (non)spaces in regex?
by Ovid
in thread Matching (non)spaces in regex?
by Guildenstern
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |