Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match alphanumeric character and ampersand(&)

Tags:

regex

I need regex to search string for alphanumeric, (, ), -, ., / and ampersand(&).

Right now i m using this regex in client side validation

 [^A-Za-z0-9.)(/-\&]

EDIT:

I want to search my string for special characters VAL.search(/[^A-Za-z0-9.)(/-\&]+/g)==-1

like image 823
key2 Avatar asked Jun 07 '11 08:06

key2


People also ask

Does Ampersand need to be escaped in regex?

Thanks. @RandomCoder_01 actually, no escapes are needed. & is not a special regex character, so no need to escape it.

What does ampersand mean in regex?

This answer is not useful. Show activity on this post. $& (dollar ampersand) holds the entire regex match. $' (dollar followed by an apostrophe or single quote) holds the part of the string after (to the right of) the regex match. $` (dollar backtick) holds the part of the string before (to the left of) the regex match ...

What does \b mean in regex?

With some variations depending on the engine, regex usually defines a word character as a letter, digit or underscore. A word boundary \bdetects a position where one side is such a character, and the other is not.


1 Answers

Escape the backslash, put the dash at the end of the character class.

[^A-Za-z0-9.)(/\\&-]

Not sure why you included ^, as this negates the character class.

like image 188
Tomalak Avatar answered Sep 24 '22 05:09

Tomalak