0

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 :)

3
  • 3
    Where is your current code failing? Commented Mar 26, 2014 at 7:48
  • My reguler expression expecting / and \ as input. And i'm new to this reguler expression. Please help me with this. Commented Mar 26, 2014 at 7:51
  • 1
    Regular - not reguler .... Commented Mar 26, 2014 at 7:58

3 Answers 3

1
/^[a-z0-9][\w\\\/]+$/i
  1. Start of line (^).
  2. [a-z0-9] - a letter or number - 1 occurrence
  3. [\w\\\/]+ - multiple occurrences of alphanumeric characters (including _) or \ or /.
  4. Line end ($).

ignore-case flag will accept both uppercase and lowercase.

[xyz] specifies a character class meaning that either x or y or z can be matched.

DEMO

If you don't consider 123_asd to be alpha-numeric, use:

/^[a-z0-9][a-z0-9\\\/]+$/i

Hope it helps!

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

Comments

0

Try this regex:

(?i)^[a-z\d][a-z\d\\/]*$

?i treats upper-case letters as lower-case letters.

Comments

0
^[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.

1 Comment

This will not accept number at start example 1a will fail. Use ^[a-zA-Z0-9]+[a-zA-Z0-9\\\/]*

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.