3

I want to find only non alphanumeric characters and only without space without '-'...

But this is not working:

REGEXP '^[a-zA-Z0-9/-:space:]*'

This regexp is valid on these data:

 'Test Cinema'
  'AMERICANII AU TALENT - SEZONUL 5, EPISODUL 12'

I dont want to find these characters, i want to find fields like this:

'Test Item;?!'
'LOCAL KOMBAT "FIERBE BULGARIA"'

How can i write a regexp which is only valid on other characters.

1
  • thank you, but this is not working, still find 'Test Cinema'
    – czupe
    Aug 15, 2012 at 15:26

3 Answers 3

6

The ^ needs to be inside the brackets for it to be a negation. When placed at the beginning of the regex ^ means that it should be matched at the beginning of the string.

Try this to match all non-empty, non-alphanumeric (including space and -) strings:

^[^a-zA-Z0-9 -]+$
4
[^a-zA-Z0-9 -]*

That would be what you want, I think.

By placing the - at the end of the [], the regex knows you mean a literal -, and you don't need to escape it with \.

Edit: To match the whole string, use this:

^[^a-zA-Z0-9 -]*$

^ and $ are used to anchor the regex to the beginning and end of the string.

4
  • @czupe - Note that the dash, unescaped, must be last in the character class, else it will be interpreted as a range of characters. Aug 15, 2012 at 15:17
  • thank you, but stil find, valid on 'Test Cinema', and i want a reg expression which is only valid on [non alphanumerical characters and non'-', non ' ']
    – czupe
    Aug 15, 2012 at 15:27
  • @czupe That's what my regex does. Do you mean that the whole string needs to be those? Aug 15, 2012 at 15:29
  • @KendallFrey: maybe i was not clear, sorry. I want to wipe, filter field wich contains only alphanumeric characters and '-' and space... I want to get fields which contains other characters for example: '!' '?' '"' (quote) and other character.
    – czupe
    Aug 15, 2012 at 15:33
1

It would be useful to have a list of things the test should match and should not match clearly defined, as it is kind of have to guess

Try

1. ^.*?[^A-Za-z0-9 -]+[A-Za-z0-9 -]*$
2. ^.*?[^A-Za-z0-9, -]+[A-Za-z0-9, -]*$

1 matches ( the first one because of the comma)

AMERICANII AU TALENT - SEZONUL 5, EPISODUL 12
Test Item;?!
LOCAL KOMBAT "FIERBE BULGARIA"

but does not match Test Cinema

2 matches

Test Item;?!
LOCAL KOMBAT "FIERBE BULGARIA" 

But does not match

Test Cinema
AMERICANII AU TALENT - SEZONUL 5, EPISODUL 12

You can play with the second one here I had to negate the newline to make it work for the sample, but just add one test per line to see whether or not it matches

1
  • exactly what i needed, unfortunately i cant run these pattern on mysql... but work on it, thank you for the "playground" marked answer...
    – czupe
    Aug 22, 2012 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.