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 are looking for this pattern.
I'm thankfully accept the
\s\w\d
groups from the previous answer, and add other delimiters and special characters as hexadecimal ASCII ranges (you can use Unicode ranges as well):You can refer here to the ASCII Codes and Unicode characters
You could simply add all your desired characters to your character class.
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.