regex - regular expression which should allow limited special characters -


can 1 tell me regular expression textfield should not allow following characters , can accept other special characters,alphabets,numbers , on :

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ @ & 

this not allow string contains of characters in part of string mentioned above.

^(?!.*[+\-&|!(){}[\]^"~*?:@&]+).*$ 

brief explanation

  • assert position @ beginning of line (at beginning of string or after line break character) ^
  • assert impossible match regex below starting @ position (negative lookahead) (?!.*[+\-&|!(){}[\]^"~*?:@&]+)
    • match single character not line break character .*
      • between 0 , unlimited times, many times possible, giving needed (greedy) *
    • match single character present in list below [+\-&|!(){}[\]^"~*?:@&]+
      • between 1 , unlimited times, many times possible, giving needed (greedy) +
      • the character "+" +
      • a "-" character \-
      • one of characters &|!(){}[” «&|!(){}[
      • a "]" character \]
      • one of characters ^"~*?:@&” «^"~*?:@&
  • match single character not line break character .*
    • between 0 , unlimited times, many times possible, giving needed (greedy) *
  • assert position @ end of line (at end of string or before line break character) $

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -