0

I am new to regular expressions. I am using java regular expressions to match the following cases:

 - DOC_BS [\bDOC_[A-Z]+] and it works fine
 - DOC_BS1

How can i match both of the above statements in single regular expression statement. Thanks.

2
  • What is the text you want to match and what is the regular expression? Your question is hard to read. Commented Jan 16, 2014 at 9:19
  • @LutzHorn was asking for regex that would match both the above cases :) Commented Jan 16, 2014 at 10:02

4 Answers 4

1

This will solve ur problem

[\bDOC_[A-Z]+[0-9] {0,1}]
Sign up to request clarification or add additional context in comments.

Comments

0

You can add \d* for zero or more digits.

Or change [A-Z] to [A-Z|\d] if digits can be on any place after underscore character.

Comments

0

if you'r okay with finding all numbers and letters after "_" extend the letter qualifier with 0-9

[\bDOC_[A-Z0-9]+]

1 Comment

like i said: "if you'r okay with finding all numbers and letters after _" proper questions result in proper answers ;-)
0

If you would rather find the letters and numbers separately, use the following:

[\bDOC_[A-Z]+[\d]*]

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.