Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
RegexBuddy Instantly and accurately analyze and test any regular expression with RegexBuddy. Save yourself the headache of figuring out the differences between regex flavors. RegexBuddy knows all the regex features and regex flavors listed in this reference. RegexBuddy also explains and emulates many more subtle differences and idiosyncrasies that are omitted here to keep this reference readable. Get your own copy of RegexBuddy now

Regular Expression Reference: Mode Modifiers

Mode modifier syntax consists of two elements that differ among regex flavors. Parentheses and a question mark are used to add the modifier to the regex. Depending on its position in the regex and the regex flavor it may affect the whole regex or part of it. If a flavor supports at least one modifier syntax, then it will also support one or more letters that can be used inside the modifier to toggle specific modes. If it doesn't, "n/a" is indicated for all letters for that flavors.

If a flavor supports mode modifiers but does not support a particular letter, it will be indicated as "no". That does not mean that the flavor doesn't have this mode at all. The flavor may still have the mode, but no option to turn it off. Modes are also not necessarily off by default. For example, in most regex flavors, ^ and $ match at the start and end of the string only by default. But the Just Great Software applications and Ruby, they match at the start and end of each line by default. In the JGsoft applications, you can turn off this mode with (?-m) while in Ruby you cannot turn off this mode at all. (?-m) affects the dot rather than the anchors in Ruby.

The table below only indicates whether each flavor supports a particular letter to toggle a particular mode. It does not indicate the defaults.

FeatureSyntaxDescriptionExample JGsoft .NET Java Perl PCRE PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
Mode modifier (?letters) at the start of the regex A mode modifier at the start of the regex affects the whole regex and overrides any options set outside the regex. (?i)a matches a and A. YESYESYESYESYESYESYESYESnonoYESYESYESnoYESnonononononono
Mode modifier (?letters) in the middle of the regex A mode modifier in the middle of the regex affects the whole regex and overrides any options set outside the regex. te(?i)st matches test, teST, TEst and TEST. nononononononononononoYESnononononononononono
Mode modifier (?letters) in the middle of the regex A mode modifier in the middle of the regex affects only the part of the regex to the right of the modifier. If the modifier is used inside a group, it only affects the part of the regex inside that group to the right of the modifier. If the regex or group uses alternation, all alternatives to the right of the modifier are affected. te(?i)st matches test and teST but not TEst or TEST. YESYESYESYESYESYESYESYESnonononoYESnonononononononono
Modifier group (?letters:regex) Non-capturing group with modifiers that affect only the part of the regex inside the group. te(?i:st) matches test and teST but not TEst or TEST. YESYESYESYESYESYESYESYESnonononoYESnonononononononono
Negative modifier (?on-off) and (?on-off:regex) Modifier letters (if any) before the hyphen are turned on, while modifier letters after the hyphen are turned off. (?i)te(?-i)st matches test and TEst but not teST or TEST. YESYESYESYESYESYESYESYESn/an/anonoYESn/anon/an/an/an/an/an/an/a
Reset modifiers (?^) Turn off all options. The caret can be followed by modifier letters to turn some options back on. (?i)te(?^)st matches test and TEst but not teST or TEST. nonono5.14nonononon/an/anononon/anon/an/an/an/an/an/an/a
Case insensitive (?i) Turn on case insensitivity. (?i)a matches a and A. YESYESYESYESYESYESYESYESn/an/aYESYESYESn/aYESn/an/an/an/an/an/an/a
Case sensitive (?c) Turn on case sensitivity. (?c)a matches a but not A. nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Free-spacing (?x) Turn on free-spacing mode to ignore whitespace between regex tokens and allow # comments. (?x)a#b matches a YESYESYESYESYESYESYESYESn/an/aYESYESYESn/aYESn/an/an/an/an/an/an/a
Exact spacing (?t) Turn on "tight" or exact spacing mode to treat whitespace and # characters as literals. (?t)a#b matches a#b nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Single-line (?s) Make the dot match all characters including line break characters. (?s).* matches ab\n\ndef in ab\n\ndef YESYESYESYESYESYESYESYESn/an/aYESYESnon/anon/an/an/an/an/an/an/a
Multi-line (?m) Make ^ and $ match at the start and end of each line. (?m)^. matches a and d in ab\n\ndef YESYESYESYESYESYESYESYESn/an/aYESYESnon/anon/an/an/an/an/an/an/a
Single-line (?m) Make the dot match all characters including line break characters. (?m).* matches ab\n\ndef in ab\n\ndef nonononononononon/an/anonoYESn/anon/an/an/an/an/an/an/a
Tcl single-line (?s) Make ^ and $ match at the start and end of the string only. Make the dot match all characters including line break characters. (?s)^.{3} matches only ab\n in ab\n\ndef nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Tcl multi-line (?m) Make ^ and $ match at the start and end of each line. Do not allow the dot and negated character classes to match line break characters. (?m)^. matches a and d in ab\n\ndef nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Tcl multi-line (?n) Make ^ and $ match at the start and end of each line. Do not allow the dot and negated character classes to match line break characters. (?n)^. matches a and d in ab\n\ndef nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Tcl "partial" newline-sensitive (?p) Make ^ and $ match at the start and end of the string only. Do not allow the dot and negated character classes to match line break characters. (?p)^.* matches only ab in ab\n\ndef nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Tcl "weird" newline-sensitive (?d) Make ^ and $ match at the start and end of each line. Make the dot match all characters including line break characters. (?w)^. matches a, the first \n, and d in ab\n\ndef nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Explicit capture (?n) Plain parentheses are non-capturing groups instead of numbered capturing groups. Only named capturing groups actually capture. (?n)(a|b)c is the same as (?:a|b)c YESYESnonononononon/an/aYESnonon/anon/an/an/an/an/an/an/a
Duplicate named groups (?J) Allow multiple named capturing groups to share the same name. (?J)(?:(?'x'a)|(?'x'b))\k'x' matches aa or bb nononono6.75.2.0YESYESn/an/anononon/anon/an/an/an/an/an/an/a
Ungreedy quantifiers (?U) Switches the syntax for greedy and lazy quantifiers. It's use is strongly discouraged because it confuses the meaning of the standard quantifier syntax. (?U)a* is lazy and (?U)a*? is greedy nonononoYESYESYESYESn/an/anononon/anon/an/an/an/an/an/an/a
UNIX lines (?d) When anchors match at line breaks and when the dot does not match line breaks, make them recognize only the line feed character as a line break (?dm)^. matches a and c in a\rb\nc nonoYESnononononon/an/anononon/anon/an/an/an/an/an/an/a
BRE (?b) Interpret the regular expression as a POSIX BRE (?b)a\+ matches aaa nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
ERE (?e) Interpret the regular expression as a POSIX ERE (?e)[a\]+ matches a\a\a nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Literal (?q) Interpret the regular expression as a literal string (excluding the modifier) (?q)[a\]+ matches [a\]+ literally nonononononononon/an/anononon/aYESn/an/an/an/an/an/an/a
Extra syntax (?X) Treat letters that are escaped with a backslash and that don't form a regex token as an error instead of as a literal. (?X)\q is an error while (?-X)\q matches q nonononoYESYESYESYESn/an/anononon/anon/an/an/an/an/an/an/a
FeatureSyntaxDescriptionExample JGsoft .NET Java Perl PCRE PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath

Make a Donation

Did this website just save you a trip to the bookstore? Please make a donation to support this site, and you'll get a lifetime of advertisement-free access to this site!

Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Anchors
Word Boundaries
Quantifiers
Unicode
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Recursion & Balancing Groups
Replacement Reference
Characters
Matched Text & Backreferences
Context & Case Conversion
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog
PowerGREP 4
PowerGREP PowerGREP is probably the most powerful regex-based text processing tool available today. A knowledge worker's Swiss army knife for searching through, extracting information from, and updating piles of files.
Use regular expressions to search through large numbers of text and binary files. Quickly find the files you are looking for, or extract the information you need. Look through just a handful of files or folders, or scan entire drives and network shares.
Search and replace using text, binary data or one or more regular expressions to automate repetitive editing tasks. Preview replacements before modifying files, and stay safe with flexible backup and undo options.
Use regular expressions to rename files, copy files, or merge and split the contents of files. Work with plain text files, Unicode files, binary files, compressed files, and files in proprietary formats such as MS Office, OpenOffice, and PDF. Runs on Windows 2000, XP, Vista, 7, 8, and 8.1.
More information
Download PowerGREP now