I use this regular expression: ^[a-zA-Z0-9]*$
to match English phrases, however, I want this expression to match English phrases that may contain some or all of these characters at the beginning, between or at the end of them:
? > < ; , { } [ ] - _ + = ! @ # $ % ^ & * | '
and also the space character.
how can I update this regular expression to satisfy this requirement ?
thank you so much in advance ...
You could simply add all your desired characters to your character class.
^[a-zA-Z0-9?><;,{}[\]\-_+=!@#$%\^&*|']*$
You will need to escape the following characters with a backslash, since they are considered as metacharacters inside character classes: ]
, -
, ^
.
Note that your regex will also match empty strings, since it uses the *
quantifier. If you only want to match words having at least one character, replace it with the +
quantifier.
You are looking for this pattern.
^[\s\w\d\?><;,\{\}\[\]\-_\+=!@\#\$%^&\*\|\']*$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With