liveBook · Manning

Regular expression

As explained in Spring Security in Action, Second Edition

A regular expression is a pattern notation for matching character sequences and strings according to specified textual rules.

A regular expression (regex) describes character or string formats for matching requests when ordinary path expressions cannot express the authorization rule. section 8.3 section 8.4

Use regexes selectively because they provide power at the cost of readability:

  • Match detailed path conditions, including symbols, characters, or combinations of path variables. section 8.3
  • Pass a RegexRequestMatcher to requestMatchers(), or configure regexMatchers() for endpoint authorization. section 8.3
  • Prefer path expressions when they are sufficient, and reserve regexes for requirements those expressions cannot handle. section 8.3

Authorize video requests

A video endpoint accepts any authenticated user when the country is the United States, Canada, or United Kingdom, or when the language is English. A regex matcher allows john to access /video/us/en but rejects /video/fr/fr; jane, with the premium authority, can access both.

How Spring Security in Action, Second Edition covers it

How deep it goes
Demonstrates matcher configuration and request outcomes, while deferring comprehensive regex syntax and recommending further study.
Examples
Uses email-domain filtering and country-language video authorization with curl requests and Java security configuration.
What it assumes
Assumes basic regular-expression knowledge without requiring expertise, and introduces its use in endpoint authorization.
What you can do after
Apply regex authorization through Spring Security request matchers and test allowed or rejected endpoint requests.
How it connects
Connects regular expressions with request matchers, path expressions, HTTP methods, and authorization.

Also explained in

Compare how 27 books explain regular expression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.