Including test for whitespace in addition to other tests as per perl template

I want to find a given string for symbolic or weird symbolic characters that occur when exporting / importing between MySQL and Excel when using a tab delimited text file.

To do this, I tried !~ /[a-zA-Z0-9]\s/

- I thought that this pattern will test the given string and identify those that contain anything other than a-z

, a-z

, 0-9

or space?

Pasting this into the inline regex tester \s

works on its own, but when I add an element a-zA-Z0-9

it cancels the white space.

White space can be anything in the string, or it can be at the beginning or end, what is the correct regex to capture it?

+3


source to share


1 answer


You can use the following regular expression for this. This will only select words that contain invalid characters.

\b\S*(?=[^A-Za-z0-9\s]+\b)\S*\b

      

Demo



Or, if you just want to grab anything other than a-zA-Z0-9 and a space, you can try this:

[^a-zA-Z0-9\s]

      

Demo2

+1


source







All Articles