1

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?

2
  • it is not clear, further explanation please Commented Sep 18, 2018 at 11:54
  • 1
    Your pattern is equal to \d{1,2}+\). Try \d{1,2}(?=\)) Commented Sep 18, 2018 at 11:55

3 Answers 3

3

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}(?=\\))";
Sign up to request clarification or add additional context in comments.

Comments

0

You can do that:

^.*\) (.*) i want t.*$

But, Let's improve the regex:

^.*\([^\)]*\) (\d+\)).*$

Comments

0

since you are saying to match only 10) try the following

\d{1,2}+\)(?!.*\d{1,2}+\))

demo and explantion here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.