1

I want a regex that accept almost all valid character i have made this regex

 "([a-zA-Z0-9]|[- @\\.#&!,:+_?*=/'\"()<>%\"])*$"

I want [] square brackets in that regex how can i place it?

FaisalAhmed
  • 3,469
  • 7
  • 46
  • 76
  • 1
    you have to escape the special character `[` with a backwards slash, so `\[`. I also suggest you use https://regex101.com/ or other services, which visualize what the regex truly is – Japu_D_Cret Apr 12 '17 at 08:43
  • 2
    Use double backslashes to escape special regex metacharacters inside a Java string literal. That also means you need to use ``\\\\``, not ``\\``, to match a literal backslash. And there is no way to put unescaped `]` and `[` inside a character class in a Java regex because they are used to form character class unions/subtractions. – Wiktor Stribiżew Apr 12 '17 at 08:43
  • Thanks @WiktorStribiżew using double backslashes worked for me \\\[ \\\] – FaisalAhmed Apr 12 '17 at 08:48

0 Answers0