0

I have the following regex that checks for characters not in the character class:

[^\w+\-:\.\(\)\"\*\?\&\|\!\{\}\[\]\^~\\@\#\/\$\%\'\= ]

I'm expecting that it doesn't match the dash '-' on the following string, however it is:

SEPCO−SEPA50PT−S−TFA−ALC18−PZ4
8
  • 1
    What's with all those slashes? Commented Nov 12, 2015 at 16:42
  • 2
    Most of those backslashes are not needed. You only need to escape meta-characters, Commented Nov 12, 2015 at 16:43
  • 1
    And most meta-characters lose their special meaning inside []. Commented Nov 12, 2015 at 16:44
  • Those are special characters I'm escaping. They are checking for literals. For example, \? checks for ?. Commented Nov 12, 2015 at 16:45
  • @MusicalShore ? is not special inside []. Commented Nov 12, 2015 at 16:45

1 Answer 1

4

The in this:

SEPCO−SEPA50PT−S−TFA−ALC18−PZ4

is not the same character as the - in your regex. It is in fact the Unicode MINUS-SIGN rather than the Unicode HYPHEN-MINUS.

Here are the two next to each other showing they're different:

-

Sign up to request clarification or add additional context in comments.

12 Comments

How do I check for that?
@MusicalShore: What do you mean? You add that character to your character class.
Yes. I also only have - on my keyboard. I don't have é on my keyboard either, but it's still a character.
@MusicalShore: You probably also don't have ü or ö on your keyboard. But those characters still exist and can appear in text.
Who knows - that's an entirely different question. What software are they using etc? You need to ask them, not us. The fact is, the character is there. As I mentioned further up, if you type a - in in the middle of a sentence in Word/Outlook etc, it gets turned into yet another dash (– EN DASH). Still looks the same, but yet another different character. Is it perhaps auto generated from somewhere? I find it hard to believe that users would be typing in a code like that?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.