DELAPARRA
Index
Color
NL
Category: Regex flags

/r (Right-to-Left)

Explained by Updated

What is /r (Right-to-Left)?

/r (Right-to-Left): Scans the input from right to left instead of left to right — matters for lookaround direction and where scanning starts. Right-to-left mode, available in .NET as RegexOptions.RightToLeft, makes the engine start at the end of the text and move backwards. The first match it reports is the last one in the string.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about /r (Right-to-Left)

How is /r (Right-to-Left) used in practice?

That is handy when you want the final occurrence of something, such as the file extension after the last dot, or the last number in a line. With normal matching you would need a greedy prefix or extra code to find it.

What should you keep in mind with /r (Right-to-Left)?

It also changes how lookarounds and some quantifiers behave, so a pattern that works left to right may give different results in this mode. Most other engines do not support it at all. If your code may move to another language, prefer a portable approach, such as matching with $ at the end, or splitting the string and taking the last part.

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.