-4

I am trying to create a regex to match any string that do not contain special characters / or \. I also want to keep the length of the string between 2 and 60 characters.

I haven't got any expertise with regex. So is there any way I can get a solution for my issue .

Maroun
  • 87,488
  • 26
  • 172
  • 226
Stuborg
  • 123
  • 1
  • 11
  • You can do this without regex. Actually you *should*. – Maroun Aug 05 '15 at 15:11
  • 1
    @MarounMaroun I disagree. Actually `[^/\]{2,60}` does the trick – Aserre Aug 05 '15 at 15:13
  • @Ploutox `[^/\\]{2,60}` actually. I don't know of an implementation where `\ ` inside a regex does not act as an escape character for `]`. – Siguza Aug 05 '15 at 15:15
  • I have tried using ^[^\\/]*$ but its not working for me – Stuborg Aug 05 '15 at 15:16
  • @Stuborg "Not working" has no meaning. Not working **how**? – Siguza Aug 05 '15 at 15:17
  • @Siguza Correct. I wrote the coment rapidly to talk about the idea. For completeness regarding OP's problem, he should also add delimiters like `^`, `$` or `\s` around this regex otherwise it will catch `foo` in `foo/` instead of rejecting the entry altogether – Aserre Aug 05 '15 at 15:18
  • can you try this...[^\/\\]{2,60} –  Aug 05 '15 at 15:23
  • how about something like ^[A-Za-z0-9\d=!\-@._*]*$ –  Aug 05 '15 at 15:40

1 Answers1

0

Escape both slashes try this:

[^\/\\]{2,60}

Demo

Arunesh Singh
  • 3,349
  • 12
  • 24