Regex any ASCII character

RegexAscii

Regex Problem Overview


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 Solutions


Solution 1 - Regex

[ -~]

It was seen here. It matches all ASCII characters from the space to the tilde.

So your implementation would be:

xxx[ -~]+xxx

Solution 2 - Regex

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

Solution 3 - Regex

You can use the [[:ascii:]] class.

Solution 4 - Regex

Since US-ASCII characters are in the byte range of 0x00–0x7F (0–127):

xxx[\x00-\x7F]+xxx

Solution 5 - Regex

Accepts / Matches only ASCII characters

/^[\x00-\x7F]*$/

Solution 6 - Regex

Try using .+ instead of [(\w)(\W)(\s)]+.

Note that this actually includes more than you need - ASCII only defines the first 128 characters.

Solution 7 - Regex

. stands for any char, so you write your regex like this:

xxx.+xxx

Solution 8 - Regex

Depending on what you mean with "ASCII character" you could simply try:

xxx.+xxx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionionView Question on Stackoverflow
Solution 1 - Regexluk3thomasView Answer on Stackoverflow
Solution 2 - RegexMatthew FlaschenView Answer on Stackoverflow
Solution 3 - RegexcatwalkView Answer on Stackoverflow
Solution 4 - RegexGumboView Answer on Stackoverflow
Solution 5 - RegexVaibhav GaikwadView Answer on Stackoverflow
Solution 6 - RegexMark ByersView Answer on Stackoverflow
Solution 7 - Regexm_vitalyView Answer on Stackoverflow
Solution 8 - RegexRoToRaView Answer on Stackoverflow