DELAPARRA
Index
Color
NL
Category: Regex flags

/x (Extended / Verbose)

Explained by Updated

What is /x (Extended / Verbose)?

/x (Extended / Verbose): Allow whitespace and # comments inside the pattern for readability. Not available in JavaScript. The x flag, called extended or verbose mode, lets you add whitespace and comments inside a regular expression. Spaces are ignored and # starts a comment, so you can lay a pattern out over several lines and explain each part.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about /x (Extended / Verbose)

How is /x (Extended / Verbose) used in practice?

It is available in PHP, Python, Perl, Ruby and .NET, but not in JavaScript. A postcode or date pattern that is unreadable on one line becomes understandable when each piece has its own line and a short note.

What should you keep in mind with /x (Extended / Verbose)?

Remember that literal spaces now need escaping, as \ or [ ], or they are ignored. If a regex is long enough that you are tempted to explain it in a comment above the code, extended mode is usually the better place for that explanation. Future readers, including you in six months, will thank you.

At a glance

CategoryRegex flags
Explained by
Updated

More Regex flags terms

All terms starting with a number or symbol

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.