0

I have the following string-

I know what that’s like when an army is defeated.

This MySQL command returns 1.

select "I know what that’s like when an army is defeated." REGEXP '[^[:punct:] A-Za-z0-9]'

But, when I use 'alnum' instead of [A-Za-z0-9], it returns 0.

select "I know what that’s like when an army is defeated." REGEXP '[^[:punct:] [:alnum:]]'

Can anyone please explain the reason?

Thanks!

0

1 Answer 1

0

HEX(CONVERT(BINARY(CONVERT("’s" USING latin1)) USING utf8)) -> C3A2E282ACE284A273 -> ’s (when utf8)

CONVERT(BINARY(CONVERT("’s" USING latin1)) USING utf8) -> ’s

So you have that's with a funny apostrophe, possibly from Microsoft Word? Furthermore it is "double encoded".

If your REGEXP trying to find 8-bit codes for further analysis, consider:

HEX(col) RLIKE '^(..)*(0[012345678BCEF]|7F|[189ABCDEF].)'

Then, if you want to 'fix' the double encoding, see my blog. Let me know if you need help picking out the parts you need.

1
  • Thanks for your answer. I understand how "’s" got end up like that but I could not understand why alnum and [A-Za-z0-9] behaved differently.
    – Naffi
    Commented Apr 3, 2015 at 5:38

Your Answer

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

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