i have following data:
somedata .test 01/45/12 2.50 data and want extract number 2.50 out of this. have managed following regex:
(?<=\d{2}\/\d{2}\/\d{2} )\d+.\d+ however doesn't work input this:
somedata .test 01/45/12 2500 data in case, want extract number 2500.
i can't seem figure out regex rule that. there way extract between 2 spaces ? extract text/number after date until next whitespace ? know date have same format , there space after text , space after number want extract.
can me out on ?
capture number between 2 whitespaces
a whitespace matched \s, , non-whitespace \s.
so, can use is:
\d{2}\/\d{2}\/\d{2} +(\s+) ^^^ see regex demo
the 1+ non-whitespace symbols captured group 1.
if - reason - need value whole match, use lookbehind approach:
(?<=\d{2}\/\d{2}\/\d{2} )\s+ or - if using pcre - may leverage match reset operator \k:
\d{2}\/\d{2}\/\d{2} +\k\s+ ^^ see another demo
note: \k , capture group approaches allow 1 or more spaces after date , more flexible.
Comments
Post a Comment