May 11, 2020 in Drupal 8

The routing system that drupal 8 offers is flexible in terms of validation. It is possible to validate your route against some typical regex lines. 

In the following mymodule.routing.yml yaml file, the {id} url parameter will be matched against the '\d+' regex, meaning a numeric character

/path/test/1 will be valid
/path/test/test will be 'page not found'

mymodule.controller:
  path: '/path/{method}/{id}'
  defaults:
    _controller: '\Drupal\mymodule\Controller\SimulationSaveController::Render'
    _title_callback: '\Drupal\vito_bos\Controller\SimulationSaveController::getTitle'
  requirements:
    _access: 'TRUE'
    id: '\d+'