Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to match 6-15 alphanumeric characters plus symbols above 1-8 keys on keyboard

Tags:

regex

I'm trying to get a regular expression that allows between 6 - 15 characters and can be a-zA-Z0-9 and the symbols above the numbers 1-8 on a keyboard.

Here's what I have but it doesn't work.

'/^[a-zA-Z0-9-_][\!\@\#\$\%\^&\*]{5,16}+$/'
like image 267
Catfish Avatar asked Feb 02 '10 23:02

Catfish


People also ask

How do you represent alphanumeric in regular expression?

For checking if a string consists only of alphanumerics using module regular expression or regex, we can call the re. match(regex, string) using the regex: "^[a-zA-Z0-9]+$".

What does \b mean in regular expressions?

The \b metacharacter matches at the beginning or end of a word.

How do you match a regular expression?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).


1 Answers

you have two different sets within brackets. Basically the expression says "1 of a-zA-Z0-9-_" followed by 5-16 of special characters. Combine them into the same set of brackets and you're all good.

Something like the following:

'/^[a-zA-Z0-9-_\!\@\#\$\%\^&\*]{5,16}$/'
like image 183
Rich Avatar answered Oct 02 '22 21:10

Rich