Reputation: 21
Example: Dear sir, No. Employee is (PM/23333999) 10) i want thank you.(MA/IERPER) i want resigned.
Hi sir,
regex : \d{1,2}+(?:(\)))
result: 10) and 99) and )
What is regex pattern can i using to get result only '10)' from split the string?
Upvotes: 1
Views: 86
Reputation: 2436
since you are saying to match only 10)
try the following
\d{1,2}+\)(?!.*\d{1,2}+\))
Upvotes: 0
Reputation: 1
You can do that:
^.*\) (.*) i want t.*$
But, Let's improve the regex:
^.*\([^\)]*\) (\d+\)).*$
Upvotes: 0
Reputation: 626738
Your pattern is equal to \d{1,2}+\)
, i.e. your pattern consumes and returns )
.
You may use
\d{1,2}(?=\))
where (?=\))
is a positive lookahead that will require the presence of )
but won't return it in the match. Also, note that {1,2}+
here will behave the same as a non-possessive, greedy {1,2}
quantifier (as there are no other ways to match the string before )
), so no need adding the +
.
See the regex demo.
In Java, declare it as
String regex = "\\d{1,2}(?=\\))";
Upvotes: 3