FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Stop writing the same regex for #[Route]
NewsWeb Development

Stop writing the same regex for #[Route]

via Dev.to WebdevStiven Llupa1mo ago

Did you know Symfony ships with a built-in class full of pre-defined route requirement patterns? It's called Requirement , and it lives in Symfony\Component\Routing\Requirement . Instead of writing your own regex for common route parameters like UUIDs, slugs, date formats, or locale codes, you can just reference a constant. So instead of this mess in your route attribute: # [ Route ( '/users/{id}' , requirements : [ 'id' => '[0-9a-f]{8}-[0-9a-f]{4}-' . '[0-9a-f]{4}-[0-9a-f]{4}-' . '[0-9a-f]{12}' , ])] public function show ( string $id ): Response { // ... } You write: # [ Route ( '/users/{id}' , requirements : [ 'id' => Requirement :: UUID , ])] public function show ( string $id ): Response { // ... } Instead of: # [ Route ( '/blog/{slug}' , requirements : [ 'slug' => '[a-z0-9]+(?:-[a-z0-9]+)*' , ])] public function post ( string $slug ): Response { // ... } You write: # [ Route ( '/blog/{slug}' , requirements : [ 'slug' => Requirement :: ASCII_SLUG , ])] public function post ( string

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
19 views

Related Articles

News

The Repressed Demand for Software

Medium Programming • 5h ago

Amazon is offering up to 50 percent off chargers from Anker and others for its Big Spring Sale
News

Amazon is offering up to 50 percent off chargers from Anker and others for its Big Spring Sale

The Verge • 5h ago

News

Reading leaked Claude Code source code

Lobsters • 5h ago

Newly Published Repositories
News

Newly Published Repositories

Medium Programming • 5h ago

Axios Gets 100 Million Downloads a Week. Today, Two Came With a Trojan.
News

Axios Gets 100 Million Downloads a Week. Today, Two Came With a Trojan.

Medium Programming • 6h ago

Discover More Articles