0

I would like to detect all these url's with a regular expression:

/liga-femenina-1
/liga-femenina-1/equipos
/liga-femenina-1/resultados
/liga-femenina-1/estadisticas
/liga-femenina-1/buscador
/liga-femenina-2
/liga-femenina-2/equipos
/liga-femenina-2/resultados
/liga-femenina-2/estadisticas
/liga-femenina-2/buscador

I have defined this regular expression:

\/liga-femenina-(1|2)\/?\w*

This regular expression only detects the first url.

enter image description here

But, If I remove the first url, the regular expression detects correctly the next url when before doesn't do it.

enter image description here

How can I make that my regular expression detects all the urls? What am I doing wrong?

José Carlos
  • 2,850
  • 12
  • 59
  • 95
  • 7
    The regex is fine. You haven't set the `gm` flags in your regex tester. Click on the flag symbol on the right – adiga Apr 25 '19 at 10:44
  • Possible duplicate of [Regex: validate a URL path with no query params](https://stackoverflow.com/questions/12928781/regex-validate-a-url-path-with-no-query-params) – Towkir Apr 25 '19 at 10:46

1 Answers1

4

Try with flag g (global):

/\/liga-femenina-(1|2)\/?\w*/g

g

global match; find all matches rather than stopping after the first match

Please Note: If you use start and end in the regex then use flag m (multiline):

/^\/liga-femenina-(1|2)\/?\w*+$/gm

m

multiline; treat beginning and end characters (^ and $) as working over multiple lines (i.e., match the beginning or end of each line (delimited by \n or \r), not only the very beginning or end of the whole input string)

Mamun
  • 66,969
  • 9
  • 47
  • 59