skip to Main Content

Using this regex: (.*)(EB([s]{0,})[0-9]{7}) to remove white spaces and able to read 7 digits after EB but its not accepting space between digits.

Currently it’s passing value with space after EB and not accepting space in b/w 7 digits.

Input string: EB 67645 89

Using value.replaceAll("s",""); in code.

2

Answers


  1. You can try this regex, it should help to solve your problem:

    (.*)(EB)s*(ds*){7}
    

    By the way you can use regex101 to play with regex, it’s very useful environment when you’re working with regexps.

    Login or Signup to reply.
  2. To match the example string you don’t need the capture groups, you can match 7 times a digit preceded by optional whitespace chars (note that it can also match newlines).

    Then you can remove the whitespace chars from this match using replaceAll:

    bEB(?:s*d){7}b
    

    In Java

    String regex = "\bEB(?:\s*\d){7}\b";
    

    Regex demo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search