Search code examples
regexqtqregularexpression

How to find two digit number that is not part of a date using regular expression


I have this long string value:

"10 12 10/05/2014 p4=34"

I would like to get only the two digit numbers (underlined):

"10 12 10/05/2014 p4=34"
 -- --               -- 

So the result should be

10 12 34

Solution

  • Have a try with:

    (?<![\d/])\d\d(?![\d/])
    

    Where:

    (?<![\d/])  : negative lookbehind, assumes there're no digits nor slashes before.
    \d\d        : 2 digits.
    (?![\d/])   : negative lookahead, assumes there're no digits nor slashes after.