In the following string:
7thousand3hundred54
I want to match:
7thousand3
3hundred54
I’m currently using this pattern:
(\d?[(1-9)]|[1-9]0)(hundred|thousand)(\d?[(1-9)]|[1-9]0)
Which matches just:
7thousand3
Which makes sense, but how can I modify the pattern such that the 3 in the middle overlaps in the two matches that I’m looking for in 7thousand3hundred54?
>Solution :
You’ve to use positive lookahead assertion, to get it to work. The simplest solution is:
(?=(\d+(hundred|thousand)\d+))
If you want the extra digit checks you had, you can use:
(?=((\d?[(1-9)]|[1-9]0)(hundred|thousand)(\d?[(1-9)]|[1-9]0)))