Reputation: 1320
I want a regular expression, which should start with alphabet or numbers and followed by alphanumeric character and in between, it may or may not contain forward or backward slash (\,/
).
Highly appreciate your help.
Thanks :)
Upvotes: 0
Views: 84
Reputation: 2192
^[a-zA-Z0-9]+[a-zA-Z0-9\/\\]*
This will accept / or \ only in between.
Edit: Oops:p Missed the numbers, updated. Thanks for pointing out.
Upvotes: 0
Reputation: 11233
Try this regex:
(?i)^[a-z\d][a-z\d\\/]*$
?i
treats upper-case letters as lower-case letters.
Upvotes: 0
Reputation: 6753
/^[a-z0-9][\w\\\/]+$/i
^
).[a-z0-9]
- a letter or number - 1 occurrence[\w\\\/]+
- multiple occurrences of alphanumeric characters (including _
) or \
or /
.$
).i
gnore-case flag will accept both uppercase and lowercase.
[xyz]
specifies a character class meaning that either x
or y
or z
can be matched.
If you don't consider 123_asd
to be alpha-numeric, use:
/^[a-z0-9][a-z0-9\\\/]+$/i
Hope it helps!
Upvotes: 1