Home > other >  regular expreseion with multimple conditions
regular expreseion with multimple conditions

Time:11-18

I need to find a regualer expression that contains the following conditions

  1. Start with /appl/
  2. Does not end with /
  3. does not contain a hyphen (-) anywhere

For example:

/appl/test01

Would be wrong:

/appl/test-01
/appl/test01/
/appl/test-01/

I have created the following and it does what I need except for the hyphen part

^\/appl\/[\W-] [/][\W-]|\/appl\/[\W-] $|[^/]$

Thank you in advance

CodePudding user response:

You can consider using

^\/appl\/[^-]*[^-\/]$

See the regex demo. Details:

  • ^ - start of string
  • \/appl\/ - /appl/ string
  • [^-]* - zero or more chars other than - as many as possible
  • [^-\/] - any char other than - and /
  • $ - end of string.
  • Related