How to allow only 1 forward slash in regex expression?

Member

by lottie , in category: Third Party Scripts , 6 days ago

How to allow only 1 forward slash in regex expression?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , 5 days ago

@lottie 

To allow only one forward slash "/" in a regular expression, you can use the following pattern:

1
^[^/]*/[^/]*$


Explanation:

  • ^ : Start of the line
  • [^/]* : Zero or more characters that are not a forward slash
  • / : The forward slash character
  • [^/]* : Zero or more characters that are not a forward slash
  • $ : End of the line


This regex pattern will only match strings that contain exactly one forward slash.