What is the regex to match xxx[any ASCII character here, spaces included]+xxx
?
I am trying xxx[(\w)(\W)(\s)]+xxx
, but it doesn't seem to work.
Regex makes it easy to match any specific ASCII character or a range of characters. A regular expression that matches ASCII characters consists of an escaped string \x00 where 00 can be any hexadecimal ASCII character code from 00 to FF.
Description. The character class \p{ASCII} matches any ascii character.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
Non-ASCII characters are those that are not encoded in ASCII, such as Unicode, EBCDIC, etc. ASCII is limited to 128 characters and was initially developed for the English language.
[ -~]
It was seen here. It matches all ASCII characters from the space to the tilde.
So your implementation would be:
xxx[ -~]+xxx
If you really mean any and ASCII (not e.g. all Unicode characters):
xxx[\x00-\x7F]+xxx
JavaScript example:
var re = /xxx[\x00-\x7F]+xxx/; re.test('xxxabcxxx') // true re.test('xxx☃☃☃xxx') // false
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