I've spent way too many minutes on this now, s开发者_JS百科o I thought I'd try my luck here instead.
I need a regex pattern that matches a whole number and everything afterwards up until another whole number appears. So in the following string:
50 !#!#€test30testtest 20!!!!`
it should match:
50 !#!#€test
30testtest
20!!!!
Is there a way to do that?
\d+\D+
does exactly that.
\d+
matches one or more digits, and \D+
matches one or more non-digits.
If you put each part in parentheses, you can then access the matches separately: (\d+)(\D+)
.
Try this: ([0-9]*[\D]*)
I tried it in rubular and here is the result for your test string:
http://rubular.com/r/qQiAbMlbQf
The following matches numbers and option all non-numbers after the number.
/[\d]+[^\d]*/
精彩评论