Regular expression

The syntax of regular expressions used by Ogo is different from the standard ones, but is closely related to RE2 regular expressions, with some specificities.

Regular expressions are used for the URL Exception and Access Control features.

They allow you to create patterns that will match the requests you want to process with the given functionality.

 

How to use it ?

The regular expressions currently used by Ogo deal with URLs, so they must start with /.

Examples:

  • /api
    Covers URLs like : '/apiv2', '/api/toto'

  • /api/ 
    Covers URLs like : '/api/toto', but not like : '/apiv2'. 

RegExp examples :

Structure : {[group_name]:[regexp]}

  • /api/articles/{id:[0-9]+}
    {id:[0-9]+} will match a number repetition.
    • Covers URLs like : /api/articles/123/anything 
    • Doesn't cover : /api/articles/anything

 

  • /api/authors/john-{name:[a-zA-Z-]+}/articles{end:$}
    {name:[a-zA-Z-]+} will match a alpha character lowercase/uppercase/hyphen repetition. {end:$} will match an end of string.
    • Covers URLs like : /api/authors/john-doe/articles 
    • Doesn't cover : api/authors/robert/articles, api/authors/john-doe/articles/anything
  •