Tutorial by Examples

Given the following input: aaaaaAlazyZgreeedyAlaaazyZaaaaa We will use two patterns: one greedy: A.*Z, and one lazy: A.*?Z. These patterns yield the following matches: A.*Z yields 1 match: AlazyZgreeedyAlaaazyZ (examples: Regex101, Rubular) A.*?Z yields 2 matches: AlazyZ and AlaaazyZ (exampl...
When you have an input with well defined boundaries and are expecting more than one match in your string, you have two options: Using lazy quantifiers; Using a negated character class. Consider the following: You have a simple templating engine, you want to replace substrings like $[foo] whe...

Page 1 of 1