1

enter image description hereI am writing a regex to satisfy the following conditions no capital letters, no spaces, no underscores, umlauts or special characters and no multiple slashes.

I have implemented this /[^a-z\/{1}\s]/g but still it allows more than one slash. Any idea what I am missing .

if(value.match(/[^a-z\/{1}\s]/g) ){
    console.log(invalid)
 }
  1. these values should fail to pass a test

  SHOULDNOTMATCH
  some_
  über
  ässs
  schleißheim
  some?sd
  some/7asa+
  some one
  shouldnotmatche//
  dont'allow
  /home//some/where/
  1. These values should pass a test

   home
   page
   thisshouldpass
   someothertext
7
  • Maybe test it out on regex101.com or similar websites. See what your regex actually matches here regex101.com/r/34U6Rz/1 Commented Feb 1, 2022 at 14:52
  • @humble_barnacle I already used that tool , as seen from the attached picture. strings with // are not matched Commented Feb 1, 2022 at 14:58
  • @anubhava your suggestion does not match anything including accepted values eg : 1. home 2. thisshouldmatch 3. page Commented Feb 1, 2022 at 15:29
  • 1
    ok then update question with accepted and not-accepted examples. Commented Feb 1, 2022 at 15:33
  • 1
    Check this working demo Commented Feb 1, 2022 at 16:00

1 Answer 1

3

Converting my comment to answer so that solution is easy to find for future visitors.

You may consider this regex for your cases:

/^[a-z]+(?:\/[a-z]*)?$/igm

Which matches 1+ letters at the start i.e. ^[a-z]+ followed by an optional group: (?:\/[a-z]*)? which means match a / followed by 0 or more letters before end position.

RegEx Demo

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

Comments

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.