-3

I'm very bad with regular expressions and I have a problem with my Symfony2 routes

This is my yml route

ilppa_adverse_view:
    path:     /{adverseReference}/{adverseName}
    defaults:
        _controller: IlppaAdverseBundle:Adverse:view
    requirements:
        adverseReference: !profile|!adverse

And I have a problem generating my route

An exception has been thrown during the rendering of a template ("Parameter "adverseReference" for route "ilppa_adverse_view" must match "!profile|!adverse" ("5401b864ad2f1" given) to generate a corresponding URL.") in FOSUserBundle:Profile:show_content.html.twig at line 16.

I don't understand because 5401b864ad2f1 match with !profile|!adverse

Ajouve
  • 8,589
  • 22
  • 77
  • 123
  • [Regular expression to match string not containing a word?](http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word) – Wouter J Aug 30 '14 at 17:15

1 Answers1

2

no it does not match: http://regex101.com/r/sB8cB5/1

in regexp you must define explicitly what match your regexp. You can not assume that if regexpr do not match two string it matches all other strings.

you must also know that for symfony default requirements for route placeholders is:

[^/]+

I played with this regexp a little bit but not tested on symfony instance, but it could work in your case:

^((?!.*(profile|adverse))[^\/]+)$

or

^((?!.*(profile|adverse))[^/]+)$

http://regex101.com/r/rS4eL4/1

you can also create custom url matcher in symfony, it is not required that this is regexp

LPodolski
  • 2,818
  • 4
  • 19
  • 23