I am trying to write some regex such that:
100 pages
and 100pages
(either "100 pages match" or " 100 pages" match. The 2nd contains a space before the token "100"
(100 pages
and (100pages
but not
1100 pages
, 1,100 pages
etc.
I'm currently using Java regex.
What I've come up with is (\\s){1}(100)(\\s){0,1}(pages)
but cannot incorporate the initial parenthesis. Hopefully I can use the |
logical operator to make my regex lean. Any suggestions?
You could use a regex like this :
[\(\s]100\s?pages
It will first match an open parenthesis or space ( [\\(\\s]
), followed by 100
, followed by an optional space ( \\s?
), followed by pages
.
So you want to match 100 pages
and 100pages
but not 1100pages
or 1,100 pages
right and you dont want the (
in regex?
Try this https://regex101.com/r/5uOlup/1
(?<!\d|\d,)100\s?pages
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.