1

I am parsing text and need to detect if any string contains any character NOT including A-Z, 0-9, full stop, comma, plus, minus, or any number of spaces.

I tried the regex expression: "[^A-Z0-9][^.][^,][^-][^+][\S+]"

as well as variations on this, which does not work correctly.

Examples of permissible strings:

1 23842U 96021A   15170.20596865  .00000124  00000-0  00000+0 0  9998
2 23842   0.0589 306.1344 0002868 147.0577 292.5546  1.00269795 70198

Invalid string:

1 2%8!2U 96021A   15170.20596865  .00000124  ^00000-0  00000+0 0  9998
Avinash Raj
  • 160,498
  • 22
  • 182
  • 229
cadebe
  • 559
  • 1
  • 10
  • 25

1 Answers1

1

Seems like you want to allow, spaces, alphabets, digits, dot, plus, minus.

Pattern p = Pattern.compile("^[A-Za-z,.+\\s\\d-]+$");
Avinash Raj
  • 160,498
  • 22
  • 182
  • 229