-2

the cases are

  • compulsory '\' char at the first
  • followed by alphanumeric
  • compulsory '\' char at the last

eg:\abc\bvc\

\abc4\abc3\abc2\abc1\

  • So basically you want a regex that limits input. Has to start and end with "\" and has one or more folders shown. – D_Bester Mar 28 '16 at 05:13

2 Answers2

1

Use ^ to match the begging of the string and $ to match the end of the string. Then use character class with word character.

The following allows only the alphanumeric characters

^\\[\w\\]+\\$

and then following allows any character.

^\\.+\\$

mkHun
  • 5,891
  • 8
  • 38
  • 85
  • Important to note that your regex doesn't allow spaces in folder names. But it does fit the OP's examples which don't use spaces. – D_Bester Mar 28 '16 at 05:27
  • 1
    Looking again: The OP did state they wanted alpha/numeric characters so yours is good. – D_Bester Mar 28 '16 at 05:33
0

Try this:

^\\(.+\\)+$

This requires \ at the beginning and end. Also can have multiple words for a single folder name. Also allows one or more folders.

Of course there are many more valid folder paths that don't meet this regex. This regex allows characters that are not valid for folder names; not sure what all the limitations are for folder names. See this question for a discussion on valid folder names.

Community
  • 1
  • 1
D_Bester
  • 5,723
  • 5
  • 35
  • 77