Jump to content

Welcome to CodeNameJessica

Welcome to CodeNameJessica!

💻 Where tech meets community.

Hello, Guest! 👋
You're just a few clicks away from joining an exclusive space for tech enthusiasts, problem-solvers, and lifelong learners like you.

🔐 Why Join?
By becoming a member of CodeNameJessica, you’ll get access to:
In-depth discussions on Linux, Security, Server Administration, Programming, and more
Exclusive resources, tools, and scripts for IT professionals
A supportive community of like-minded individuals to share ideas, solve problems, and learn together
Project showcases, guides, and tutorials from our members
Personalized profiles and direct messaging to collaborate with other techies

🌐 Sign Up Now and Unlock Full Access!
As a guest, you're seeing just a glimpse of what we offer. Don't miss out on the complete experience! Create a free account today and start exploring everything CodeNameJessica has to offer.

  • Entries

    47
  • Comments

    0
  • Views

    6655

Entries in this blog

In previous sections, we explored how literal characters and character classes operate in regular expressions. These match specific characters in a string. Anchors, however, are different. They match positions in the string rather than characters, allowing you to "anchor" your regex to the start or end of a string or line.


Using the Caret (^) Anchor

The caret (^) matches the position before the first character of the string. For example:

  • ^a applied to "abc" matches "a."

  • ^b does not match "abc" because "b" is not the first character of the string.

The caret is useful when you want to ensure that a match occurs at the very beginning of a string.

Example:

Regex

String

Matches

^a

"abc"

Yes

^b

"abc"

No


Using the Dollar Sign ($) Anchor

The dollar sign ($) matches the position after the last character of the string. For example:

  • c$ matches "c" in "abc."

  • a$ does not match "abc" because "a" is not the last character.

Example:

Regex

String

Matches

c$

"abc"

Yes

a$

"abc"

No


Practical Use Cases

Anchors are essential for validating user input. For instance, if you want to ensure a user inputs only an integer number, using \d+ will accept any input containing digits, even if it includes letters (e.g., "abc123").

Instead, use ^\d+$ to enforce that the entire string consists only of digits from start to finish.

Example in Perl:

if ($input =~ /^\d+$/) {
    print "Valid integer";
} else {
    print "Invalid input";
}

To handle potential leading or trailing whitespace, use:

  • ^\s+ to match leading whitespace.

  • \s+$ to match trailing whitespace.

In Perl, you can trim whitespace like this:

$input =~ s/^\s+|\s+$//g;

Multi-Line Mode

If your string contains multiple lines, you might want to match the start or end of each line instead of the entire string. Multi-line mode changes the behavior of the anchors:

  • ^ matches at the start of each line.

  • $ matches at the end of each line.

Example:

Given the string:

first line
second line
  • ^s matches "s" in "second line" when multi-line mode is enabled.

Activating Multi-Line Mode

In Perl, use the m flag:

m/^regex$/m;

In .NET, specify RegexOptions.Multiline:

Regex.Match("string", "regex", RegexOptions.Multiline);

In tools like EditPad Pro, GNU Emacs, and PowerGREP, multi-line mode is enabled by default.


Permanent Start and End Anchors

The anchors \A and \Z match the start and end of the string, respectively, regardless of multi-line mode:

  • \A: Matches only at the start of the string.

  • \Z: Matches only at the end of the string, before any newline character.

  • \z: Matches only at the very end of the string, including after a newline character.

For example:

Regex

String

Matches

\Aabc

"abc"

Yes

abc\Z

"abc\n"

Yes

abc\z

"abc\n"

No

Some regex flavors, like JavaScript, POSIX, and XML, do not support \A and \Z. In such cases, use the caret (^) and dollar sign ($) instead.


Zero-Length Matches

Anchors match positions rather than characters, resulting in zero-length matches. For example:

  • ^ matches the start of a string.

  • $ matches the end of a string.

Example:

Using ^\d*$ to validate a number will accept an empty string. This happens because the regex matches the position at the start of the string and the zero-length match caused by the star quantifier.

To avoid this, ensure your regex accounts for actual input:

^\d+$

Adding a Prefix to Each Line

In some scenarios, you may want to add a prefix to each line of a multi-line string. For example, to prepend a "> " to each line in an email reply, use multi-line mode:

Example in VB.NET:

Dim Quoted As String = Regex.Replace(Original, "^", "> ", RegexOptions.Multiline)

This regex matches the start of each line and inserts the prefix "> " without removing any characters.


Special Cases with Line Breaks

There is an exception to how $ and \Z behave. If the string ends with a line break, $ and \Z match before the line break, not at the very end of the string.

For example:

  • The string "joe\n" will match ^[a-z]+$ and \A[a-z]+\Z.

  • However, \A[a-z]+\z will not match because \z requires the match to be at the very end of the string, including after the newline.

Use \z to ensure a match at the absolute end of the string.


Looking Inside the Regex Engine

Let’s see what happens when we apply ^4$ to the string:

749
486
4

In multi-line mode, the regex engine processes the string as follows:

  1. The engine starts at the first character, "7". The ^ matches the position before "7".

  2. The engine advances to 4, and ^ cannot match because it is not preceded by a newline.

  3. The process continues until the engine reaches the final "4", which is preceded by a newline.

  4. The ^ matches the position before "4", and the engine successfully matches 4.

  5. The engine attempts to match $ at the position after "4", and it succeeds because it is the end of the string.

The regex engine reports the match as "4" at the end of the string.


Caution for Programmers

When working with anchors, be mindful of zero-length matches. For example, $ can match the position after the last character of the string. Querying for String[Regex.MatchPosition] may result in an access violation or segmentation fault if the match position points to the void after the string. Handle these cases carefully in your code.

Table of Contents

  1. Regular Expression Tutorial

  2. Different Regular Expression Engines

  3. Literal Characters

  4. Special Characters

  5. Non-Printable Characters

  6. First Look at How a Regex Engine Works Internally

  7. Character Classes or Character Sets

  8. The Dot Matches (Almost) Any Character

  9. Start of String and End of String Anchors

  10. Word Boundaries

  11. Alternation with the Vertical Bar or Pipe Symbol

  12. Optional Items

  13. Repetition with Star and Plus

  14. Grouping with Round Brackets

  15. Named Capturing Groups

  16. Unicode Regular Expressions

  17. Regex Matching Modes

  18. Possessive Quantifiers

  19. Understanding Atomic Grouping in Regular Expressions

  20. Understanding Lookahead and Lookbehind in Regular Expressions (Lookaround)

  21. Testing Multiple Conditions on the Same Part of a String with Lookaround

  22. Understanding the \G Anchor in Regular Expressions

  23. Using If-Then-Else Conditionals in Regular Expressions

  24. XML Schema Character Classes and Subtraction Explained

  25. Understanding POSIX Bracket Expressions in Regular Expressions

  26. Adding Comments to Regular Expressions: Making Your Regex More Readable

  27. Free-Spacing Mode in Regular Expressions: Improving Readability

The dot, or period, is one of the most versatile and commonly used metacharacters in regular expressions. However, it is also one of the most misused.

The dot matches any single character except for newline characters. In most regex flavors discussed in this tutorial, the dot does not match newlines by default. This behavior stems from the early days of regex when tools were line-based and processed text line by line. In such cases, the text would not contain newline characters, so the dot could safely match any character.

In modern tools, you can enable an option to make the dot match newline characters as well. For example, in tools like RegexBuddy, EditPad Pro, or PowerGREP, you can check a box labeled "dot matches newline."


Single-Line Mode

In Perl, the mode that makes the dot match newline characters is called single-line mode. You can activate this mode by adding the s flag to the regex, like this:

m/^regex$/s;

Other languages and regex libraries, such as the .NET framework, have adopted this terminology. In .NET, you can enable single-line mode by using the RegexOptions.Singleline option:

Regex.Match("string", "regex", RegexOptions.Singleline);

In most programming languages and libraries, enabling single-line mode only affects the behavior of the dot. It has no impact on other aspects of the regex.

However, some languages like JavaScript and VBScript do not have a built-in option to make the dot match newlines. In such cases, you can use a character class like [\s\S] to achieve the same effect. This class matches any character that is either whitespace or non-whitespace, effectively matching any character.


Use The Dot Sparingly

The dot is a powerful metacharacter that can make your regex very flexible. However, it can also lead to unintended matches if not used carefully. It is easy to write a regex with a dot and find that it matches more than you intended.

Consider the following example:

If you want to match a date in mm/dd/yy format, you might start with the regex:

\d\d.\d\d.\d\d

This regex appears to work at first glance, as it matches "02/12/03". However, it also matches "02512703", where the dots match digits instead of separators.

A better solution is to use a character class to specify valid date separators:

\d\d[- /.]\d\d[- /.]\d\d

This regex matches dates with dashes, spaces, dots, or slashes as separators. Note that the dot inside a character class is treated as a literal character, so it does not need to be escaped.

This regex is still not perfect, as it will match "99/99/99". To improve it further, you can use:

[0-1]\d[- /.][0-3]\d[- /.]\d\d

This regex ensures that the month and day parts are within valid ranges. How perfect your regex needs to be depends on your use case. If you are validating user input, the regex must be precise. If you are parsing data files from a known source, a less strict regex might be sufficient.


Use Negated Character Sets Instead of the Dot

Using the dot can sometimes result in overly broad matches. Instead, consider using negated character sets to specify what characters you do not want to match.

For example, to match a double-quoted string, you might be tempted to use:

".*"

At first, this regex seems to work well, matching "string" in:

Put a "string" between double quotes.

However, if you apply it to:

Houston, we have a problem with "string one" and "string two". Please respond.

The regex will match:

"string one" and "string two"

This is not what you intended. The dot matches any character, and the star (*) quantifier allows it to match across multiple strings, leading to an overly greedy match.

To fix this, use a negated character set instead of the dot:

"[^"]*"

This regex matches any sequence of characters that are not double quotes, enclosed within double quotes. If you also want to prevent matching across multiple lines, use:

"[^"\r\n]*"

This regex ensures that the match does not include newline characters.

By using negated character sets instead of the dot, you can make your regex patterns more precise and avoid unintended matches.

Table of Contents

  1. Regular Expression Tutorial

  2. Different Regular Expression Engines

  3. Literal Characters

  4. Special Characters

  5. Non-Printable Characters

  6. First Look at How a Regex Engine Works Internally

  7. Character Classes or Character Sets

  8. The Dot Matches (Almost) Any Character

  9. Start of String and End of String Anchors

  10. Word Boundaries

  11. Alternation with the Vertical Bar or Pipe Symbol

  12. Optional Items

  13. Repetition with Star and Plus

  14. Grouping with Round Brackets

  15. Named Capturing Groups

  16. Unicode Regular Expressions

  17. Regex Matching Modes

  18. Possessive Quantifiers

  19. Understanding Atomic Grouping in Regular Expressions

  20. Understanding Lookahead and Lookbehind in Regular Expressions (Lookaround)

  21. Testing Multiple Conditions on the Same Part of a String with Lookaround

  22. Understanding the \G Anchor in Regular Expressions

  23. Using If-Then-Else Conditionals in Regular Expressions

  24. XML Schema Character Classes and Subtraction Explained

  25. Understanding POSIX Bracket Expressions in Regular Expressions

  26. Adding Comments to Regular Expressions: Making Your Regex More Readable

  27. Free-Spacing Mode in Regular Expressions: Improving Readability

In addition to the question mark, regex provides two more repetition operators: the asterisk (*) and the plus (+).


Basic Usage

The * (star) matches the preceding token zero or more times. The + (plus) matches the preceding token one or more times.

For example:

<[A-Za-z][A-Za-z0-9]*>

This pattern matches HTML tags without attributes:

  • <[A-Za-z] matches the first letter.

  • [A-Za-z0-9]* matches zero or more alphanumeric characters after the first letter.

This regex will match tags like:

  • <B>

  • <HTML>

If you used + instead of *, the regex would require at least one alphanumeric character after the first letter, making it match:

  • <HTML> but not <1>.


Limiting Repetition

Modern regex flavors allow you to limit repetitions using curly braces ({}).

Syntax:

{min,max}
  • min: Minimum number of matches.

  • max: Maximum number of matches.

Examples:

  • {0,} is equivalent to *.

  • {1,} is equivalent to +.

  • {3} matches exactly three repetitions.

Example:

\b[1-9][0-9]{3}\b

This pattern matches numbers between 1000 and 9999.

\b[1-9][0-9]{2,4}\b

This pattern matches numbers between 100 and 99999.

The word boundaries (\b) ensure that only complete numbers are matched.


Watch Out for Greediness!

All repetition operators (*, +, and {}) are greedy by default. This means the regex engine will try to match as much text as possible.

Example:

Consider the pattern:

<.+>

When applied to the string:

This is a <EM>first</EM> test.

You might expect it to match <EM> and </EM> separately. However, it will match <EM>first</EM> instead.

This happens because the + is greedy and matches as many characters as possible.


Looking Inside the Regex Engine

The first token in the regex is <, which matches the first < in the string.

The next token is the . (dot), which matches any character except newlines. The + causes the dot to repeat as many times as possible:

  1. The dot matches E, then M, and so on.

  2. It continues matching until the end of the string.

  3. At this point, the > token fails to match because there are no more characters left.

The engine then backtracks and tries to reduce the match length until > matches the next character.

The final match is <EM>first</EM>.


Laziness Instead of Greediness

To fix this issue, make the quantifier lazy by adding a question mark (?😞

<.+?>

This tells the engine to match as few characters as possible.

  1. The < matches the first <.

  2. The . matches E.

  3. The engine checks for > and finds a match right after EM.

The final match is <EM>, which is what we intended.


An Alternative to Laziness

Instead of using lazy quantifiers, you can use a negated character class:

<[^>]+>

This pattern matches any sequence of characters that are not >, followed by >. It avoids backtracking and improves performance.

Example:

Given the string:

This is a <EM>first</EM> test.

The regex <[^>]+> will match:

  • <EM>

  • </EM>

This approach is more efficient because it reduces backtracking, which can significantly improve performance in large datasets or tight loops.

The *, +, and {} quantifiers control repetition in regex. They are greedy by default, but you can make them lazy by adding a question mark (?). Using negated character classes is another way to handle repetition efficiently without backtracking.

Table of Contents

  1. Regular Expression Tutorial

  2. Different Regular Expression Engines

  3. Literal Characters

  4. Special Characters

  5. Non-Printable Characters

  6. First Look at How a Regex Engine Works Internally

  7. Character Classes or Character Sets

  8. The Dot Matches (Almost) Any Character

  9. Start of String and End of String Anchors

  10. Word Boundaries

  11. Alternation with the Vertical Bar or Pipe Symbol

  12. Optional Items

  13. Repetition with Star and Plus

  14. Grouping with Round Brackets

  15. Named Capturing Groups

  16. Unicode Regular Expressions

  17. Regex Matching Modes

  18. Possessive Quantifiers

  19. Understanding Atomic Grouping in Regular Expressions

  20. Understanding Lookahead and Lookbehind in Regular Expressions (Lookaround)

  21. Testing Multiple Conditions on the Same Part of a String with Lookaround

  22. Understanding the \G Anchor in Regular Expressions

  23. Using If-Then-Else Conditionals in Regular Expressions

  24. XML Schema Character Classes and Subtraction Explained

  25. Understanding POSIX Bracket Expressions in Regular Expressions

  26. Adding Comments to Regular Expressions: Making Your Regex More Readable

  27. Free-Spacing Mode in Regular Expressions: Improving Readability

The \b metacharacter is an anchor, similar to the caret (^) and dollar sign ($). It matches a zero-length position called a word boundary. Word boundaries allow you to perform “whole word” searches in a string using patterns like \bword\b.


What is a Word Boundary?

A word boundary occurs at three possible positions in a string:

  1. Before the first character if it is a word character.

  2. After the last character if it is a word character.

  3. Between two characters where one is a word character and the other is a non-word character.

A word character includes letters, digits, and the underscore ([a-zA-Z0-9_]). Non-word characters are everything else.


Example Usage

The pattern \bword\b matches the word "word" only if it appears as a standalone word in the text.

Regex

String

Matches

\b4\b

"There are 44 sheets"

No

\b4\b

"Sheet number 4 is here"

Yes

Digits are considered word characters, so \b4\b will match a standalone "4" but not when it is part of "44."


Negated Word Boundaries

The \B metacharacter is the negated version of \b. It matches any position that is not a word boundary.

Regex

String

Matches

\Bis\B

"This is a test"

No

\Bis\B

"This island is beautiful"

Yes

\Bis\B would match "is" only if it appears within a word, such as in "island," but not if it appears as a standalone word.


Looking Inside the Regex Engine

Let’s see how the regex \bis\b works on the string "This island is beautiful":

  1. The engine starts with \b at the first character "T." Since \b is zero-width, it checks the position before "T." It matches because "T" is a word character, and the position before it is the start of the string.

  2. The engine then checks the next token, i, which does not match "T," so it moves to the next position.

  3. The engine continues checking until it finds a match at the second "is." The final \b matches before the space after "is," confirming a complete match.


Tcl Word Boundaries

Most regex flavors use \b for word boundaries. However, Tcl uses different syntax:

  • \y matches a word boundary.

  • \Y matches a non-word boundary.

  • \m matches only the start of a word.

  • \M matches only the end of a word.

For example, in Tcl:

  • \mword\M matches "word" as a whole word.

In most flavors, you can achieve the same with \bword\b.


Emulating Tcl Word Boundaries

If your regex flavor supports lookahead and lookbehind, you can emulate Tcl’s \m and \M:

  • (?<!\w)(?=\w): Emulates \m.

  • (?<=\w)(?!\w): Emulates \M.

For flavors without lookbehind, use:

  • \b(?=\w) to emulate \m.

  • \b(?!\w) to emulate \M.


GNU Word Boundaries

GNU extensions to POSIX regular expressions support \b and \B. Additionally, GNU regex introduces:

  • \<: Matches the start of a word (like Tcl’s \m).

  • \>: Matches the end of a word (like Tcl’s \M).

These additional tokens provide flexibility when working with word boundaries in GNU-based tools.


Summary

Word boundaries are crucial for identifying standalone words in text. They prevent partial matches within larger words and ensure more precise regex patterns. Understanding how to use \b, \B, and their equivalents in various regex flavors will help you craft better, more accurate regular expressions.

Table of Contents

  1. Regular Expression Tutorial

  2. Different Regular Expression Engines

  3. Literal Characters

  4. Special Characters

  5. Non-Printable Characters

  6. First Look at How a Regex Engine Works Internally

  7. Character Classes or Character Sets

  8. The Dot Matches (Almost) Any Character

  9. Start of String and End of String Anchors

  10. Word Boundaries

  11. Alternation with the Vertical Bar or Pipe Symbol

  12. Optional Items

  13. Repetition with Star and Plus

  14. Grouping with Round Brackets

  15. Named Capturing Groups

  16. Unicode Regular Expressions

  17. Regex Matching Modes

  18. Possessive Quantifiers

  19. Understanding Atomic Grouping in Regular Expressions

  20. Understanding Lookahead and Lookbehind in Regular Expressions (Lookaround)

  21. Testing Multiple Conditions on the Same Part of a String with Lookaround

  22. Understanding the \G Anchor in Regular Expressions

  23. Using If-Then-Else Conditionals in Regular Expressions

  24. XML Schema Character Classes and Subtraction Explained

  25. Understanding POSIX Bracket Expressions in Regular Expressions

  26. Adding Comments to Regular Expressions: Making Your Regex More Readable

  27. Free-Spacing Mode in Regular Expressions: Improving Readability

Regular expressions can quickly become complex and difficult to understand, especially when dealing with long patterns. To make them easier to read and maintain, many modern regex engines allow you to add comments directly into your regex patterns. This makes it possible to explain what each part of the expression does, reducing confusion and improving readability.


How to Add Comments in Regular Expressions

The syntax for adding a comment inside a regex is:

(?#comment)
  • The text inside the parentheses after ?# is treated as a comment.

  • The regex engine ignores everything inside the comment until it encounters a closing parenthesis ).

  • The comment can be anything you want, as long as it does not include a closing parenthesis.

For example, here’s a regex to match a valid date in the format yyyy-mm-dd, with comments to explain each part:

(?#year)(19|20)\d\d[- /.](?#month)(0[1-9]|1[012])[- /.](?#day)(0[1-9]|[12][0-9]|3[01])

This regex is much more understandable with comments:

  • (?#year): Marks the section that matches the year.

  • (?#month): Marks the section that matches the month.

  • (?#day): Marks the section that matches the day.

Without these comments, the regex would be difficult to decipher at a glance.


Benefits of Using Comments in Regular Expressions

Adding comments to your regex patterns offers several benefits:

  1. Improves readability: Comments clarify the purpose of each section of your regex, making it easier to understand.

  2. Simplifies maintenance: If you need to update a regex later, comments make it easier to remember what each part of the pattern does.

  3. Helps collaboration: When sharing regex patterns with others, comments make it easier for them to follow your logic.


Using Free-Spacing Mode for Better Formatting

In addition to inline comments, many regex engines also support free-spacing mode, which allows you to add spaces and line breaks to your regex without affecting the match.

Free-spacing mode makes your regex more structured and readable by allowing you to organize it into logical sections. To enable free-spacing mode:

  • In Perl, PCRE, Python, and Ruby, use the /x modifier to activate free-spacing mode.

  • In .NET, use the RegexOptions.IgnorePatternWhitespace option.

  • In Java, use the Pattern.COMMENTS flag.

Here’s an example of how free-spacing mode can improve the readability of a regex:

Without Free-Spacing Mode:

(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])

With Free-Spacing Mode and Comments:

(?#year) (19|20) \d\d        # Match years 1900 to 2099
[- /.]                       # Separator (dash, slash, or dot)
(?#month) (0[1-9] | 1[012])  # Match months 01 to 12
[- /.]                       # Separator
(?#day) (0[1-9] | [12][0-9] | 3[01])  # Match days 01 to 31

The second version is far easier to read and maintain.


Which Regex Engines Support Comments?

Most modern regex engines support the (?#comment) syntax for adding comments, including:

Regex Engine

Supports Comments?

Supports Free-Spacing Mode?

JGsoft

Yes

Yes

.NET

Yes

Yes

Perl

Yes

Yes

PCRE

Yes

Yes

Python

Yes

Yes

Ruby

Yes

Yes

Java

No

Yes (via Pattern.COMMENTS)


Example: Using Comments to Document a Complex Regex

Here’s an example of a more complex regex that extracts email addresses from a text file. Without comments, the regex looks like this:

\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b

Adding comments and using free-spacing mode makes it much more understandable:

\b                      # Word boundary to ensure we're at the start of a word
[A-Za-z0-9._%+-]+       # Local part of the email (before @)
@                       # At symbol
[A-Za-z0-9.-]+          # Domain name
\.                      # Dot before the top-level domain
[A-Za-z]{2,}            # Top-level domain (e.g., com, net, org)
\b                      # Word boundary to ensure we're at the end of a word

Key Points to Remember

  • Comments in regex are added using the (?#comment) syntax.

  • Free-spacing mode makes regex patterns more readable by allowing spaces and line breaks.

  • Supported engines include JGsoft, .NET, Perl, PCRE, Python, and Ruby.

  • Java supports free-spacing mode but does not support inline comments.


When to Use Comments and Free-Spacing Mode

Use comments and free-spacing mode when:

  1. Your regex pattern is complex and hard to read.

  2. You’re working on a team and need to make your patterns understandable to others.

  3. You need to revisit your regex after some time and want to avoid deciphering cryptic patterns.

Adding comments and using free-spacing mode can greatly enhance the readability and maintainability of your regular expressions. Complex patterns become easier to understand, update, and share with others. When working with modern regex engines, take advantage of these features to write cleaner, more maintainable regex patterns.

By making your regex more human-readable, you’ll save time and reduce frustration when dealing with intricate text-processing tasks.

Table of Contents

  1. Regular Expression Tutorial

  2. Different Regular Expression Engines

  3. Literal Characters

  4. Special Characters

  5. Non-Printable Characters

  6. First Look at How a Regex Engine Works Internally

  7. Character Classes or Character Sets

  8. The Dot Matches (Almost) Any Character

  9. Start of String and End of String Anchors

  10. Word Boundaries

  11. Alternation with the Vertical Bar or Pipe Symbol

  12. Optional Items

  13. Repetition with Star and Plus

  14. Grouping with Round Brackets

  15. Named Capturing Groups

  16. Unicode Regular Expressions

  17. Regex Matching Modes

  18. Possessive Quantifiers

  19. Understanding Atomic Grouping in Regular Expressions

  20. Understanding Lookahead and Lookbehind in Regular Expressions (Lookaround)

  21. Testing Multiple Conditions on the Same Part of a String with Lookaround

  22. Understanding the \G Anchor in Regular Expressions

  23. Using If-Then-Else Conditionals in Regular Expressions

  24. XML Schema Character Classes and Subtraction Explained

  25. Understanding POSIX Bracket Expressions in Regular Expressions

  26. Adding Comments to Regular Expressions: Making Your Regex More Readable

  27. Free-Spacing Mode in Regular Expressions: Improving Readability

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.