samedi 27 juin 2015

regex validating url

I have the following urls as subjects

localhost/hx
localhost/h.php
localhost/h/x
localhost/h/x/y
localhsot/h?hello
localhost/h

Currently my pattern is something like /localhost/h[/]*/i, but this does not work.

I do not want to match line 1 or 2, but the others are valid.

  • Problem 1: I am not able to make / or ? optional, if I remove * from the pattern it does not match localhost/h.

  • Problem 2: I am not able to escape ? for line 5, I tried \\ and \ but neither worked.

Aucun commentaire:

Enregistrer un commentaire