Reputation: 4929
How Do I match a special sign in regex?
– is not the same as -; – is longer and seems to have a different character code
I did not think of testing for the special character.
Example string I need to check:
Testshop – Best fan ware | Example shop
Should return
Testshop
The regex I use:
/[^\|\-\;\–]*/
However it does not return the correct result. The problem is the – character.
Upvotes: 0
Views: 69
Reputation: 369094
\
is unnecessary except for -
(dash).
>> 'Testshop – Best fan ware | Example shop'[/[^|\-;–]*/]
=> "Testshop "
If you want only alpha-numeric chracter, use \w+
(also match _
):
>> 'Testshop – Best fan ware | Example shop'[/\w+/]
=> "Testshop"
Upvotes: 3