regex - How to generate Regexp matcher for String with even Number? -
this question has answer here:
- regular expression match odd or number 3 answers
there're regexp digit everywhere: example:
4
but regexp number: example :
568
regex designed find pattern in string, not find , recognize e.g. (extract prime number string). should better extract consecutive digits , check (num % 2 == 0).
but still if want stick regex, pattern provided in comments above needs little bit adjustment case.
you may try pattern:
\b(\d+??[02468])\b
demo
edit:
i didn't interacted grep before, from doc found grep doesn't support features supported regex engine other languages.
so adjusted pattern based on allowed input, try pattern:
^([0-9]+[24680]|[02468])$
tested here on following inputs:
(z + (758+1) + x) (z + (757+1) + x) (z + (123+1) + x) 757 758 123 144 13 14 2
and result is:
758 144 14 2
hope helps now!
Comments
Post a Comment