in reply to Re: Matching a pattern two or four times
in thread Matching a pattern two or four times
2 things. First, you can't have multiple matches (//g) AND have your regex anchored at the start of the string.
Second, the //g will return all the captured matches, so you don't need that last +. In fact, you can't HAVE that last +, or it doesn't work.
Of course, demerphq made a very good point about that regex not being sufficient to match all numbers...my @lines = ("a 1 2", "b 3 4 5 6", "c 7 8 9"); foreach (@lines) { # you can't match multiple times starting at ^! my @list = m/(\s+\d+)/g; # no last + print @list, "\n"; }
|
|---|