Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to detect ASCII art on a single line.

Basically I want to find ASCII Art on one line. For me this is any 2 characters that are not alpha numeric ignoring whitespace. So a line might look like :

This is a !# Test of --> ASCII art detection @#@ <--

So the matches I should get are :

!#

-->

@#@

<--

I came up with this which still selects spaces :(

\b\W{2,}

Im using the following website for testing : http://gskinner.com/RegExr/

Thanks for the help its much appreciated!!

like image 200
user3200306 Avatar asked Jan 22 '26 05:01

user3200306


1 Answers

I'd suggest something like this:

[^\w\s]{2,}

This will match any sequence of two or more characters that are not word characters (which include alphanumeric characters and underscores) or whitespace characters.

Demonstration

If you would also like to match underscores as part of your 'ASCII art', you'd have to be more specific:

[^a-zA-Z0-9\s]{2,}

Demonstration

like image 84
p.s.w.g Avatar answered Jan 23 '26 19:01

p.s.w.g