0

I have given file name as

B-018 MyName

I want to check whether first four characters are in format of

'B-< Numeric >< Numeric >< Numeric >

B- will be constant for all names and i want to check if three succeeding characters are numeric.

How to do it using Regular Expressions in Java?

fatherazrael
  • 5,511
  • 16
  • 71
  • 155
  • 2
    You should really look at some basic regular expression syntax :). Or show us what you've tried – TheLostMind Nov 24 '16 at 06:16
  • Check this out http://stackoverflow.com/questions/237061/using-regular-expressions-to-extract-a-value-in-java – cheffe Nov 24 '16 at 06:19

1 Answers1

0

The following expression implements your requirement.

java.util.regex.Pattern.compile("B-\\d{3} .*").matcher("B-018 MyName").matches()

It checks that the expressions is "B-(3-digits) (any character zero or more time)".

I advise you to use a site as https://regex101.com/ to learn some basis about regex and test your expressions. This expression can be retrieved using this link https://regex101.com/r/B0GN8F/1.

Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82