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.

Most regular expression engines discussed in this tutorial support the following four matching modes:

Modifier

Description

/i

Makes the regex case-insensitive.

/s

Enables "single-line mode," making the dot (.) match newlines.

/m

Enables "multi-line mode," allowing caret (^) and dollar ($) to match at the start and end of each line.

/x

Enables "free-spacing mode," where whitespace is ignored, and # can be used for comments.

Specifying Modes Inside The Regular Expression

You can specify these modes within a regex using mode modifiers. For example:

  • (?i) turns on case-insensitive matching.

  • (?s) enables single-line mode.

  • (?m) enables multi-line mode.

  • (?x) enables free-spacing mode.

Example:

(?i)hello matches "HELLO"

Turning Modes On and Off for Only Part of the Regex

Modern regex flavors allow you to apply modifiers to specific parts of the regex:

  • (?i-sm) turns on case-insensitive mode while turning off single-line and multi-line modes.

To apply a modifier to only a part of the regex, you can use the following syntax:

(?i)word(?-i)Word

This pattern makes "word" case-insensitive but "Word" case-sensitive.

Modifier Spans

Modifier spans apply modes to a specific section of the regex:

  • (?i:word) makes "word" case-insensitive.

  • (?i:case)(?-i:sensitive) applies mixed modes within the regex.

Example:

(?i:ignorecase)(?-i:casesensitive)

Understanding matching modes is essential for writing efficient and accurate regex patterns. By leveraging modes like case-insensitivity, single-line, multi-line, and free-spacing, you can create more flexible and maintainable 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

0 Comments

Recommended Comments

There are no comments to display.

Guest
Add a comment...

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.