0

Can anyone explain me what this javascript patter actually looking for?

var pattern = /^\/.*\/$/i;
frhack
  • 4,061
  • 2
  • 25
  • 22
Ruslan Lomov
  • 475
  • 1
  • 7
  • 20

2 Answers2

3

It looks for strings that:

  • start with /
  • end with /
  • have zero or more char (any char) between the two /

Please note:

  • ^ means start of the pattern
  • $ mean end of the pattern
  • . mean any char
  • * mean zero or more
frhack
  • 4,061
  • 2
  • 25
  • 22
2

Here's he best tutorial on RegEx I've found on the Internet. You might've solved your problem just by looking at the table to the right on the page of the tutorial. Just spend an hour on this. It helped me a lot!

In the example you've provided:

^…$     Starts and ends
.   Any Character
*   Zero or more repetitions
OlehZiniak
  • 743
  • 11
  • 24