Solid Fluid System Solutions  
Home Software About Hardware Firmware
Folder Icon Worked Example
 
A simple example that shows how to import data into MS Excel. The demonstraton shows how regex removes the repetitive graft.

Document Icon Regex
Document Icon Characters
 
How to specify which characters should match at an arbitary position within a search text.
Document Icon Positioning
 
How to make matches position themselves in relation to non text entities in the search text.
Current Document Icon Repeat
 
How to repeat the preceeding token match.
Document Icon Groups
 
How to group tokens together for use in repetitions, references or alternatives.
Document Icon Special Groups
 
How to create metatoken, conditional and comment groups.
Document Icon Modes
 
How to control the overal mode of a regular expression.

Repetition

This page describes how to repeat the preceeding token match.

N.B. - When experimenting with greediness and laziness, note that although the repeater is associted with (and repeats) the token on it's left, it is terminated by the token on it's right. The token on the right of the repeater is by no means compulsory, but it's absence makes the difference between greedy and lazy negligable. On consideration, this knowledge will yield the practical usefulness of the greedy/lazy distinction.

Character Description Example

Ways to specify common repeats

? "question mark" Specifies an optional token. abc? matches ab or abc
* "greedy star" Repeats the token zero or more times. This repeat is greedy, it will attempt to match the greatest possible number of repeats in the current token. ".*" matches "def" "ghi" in abc "def" "ghi" jkl
*? "lazy star" Repeats the token zero or more times. This repeat is lazy, it will attempt to match the fewest possible number of repeats in the current token. ".*?" matches "def" in abc "def" "ghi" jkl
+ "greedy plus" Repeats the token one or more times. This repeat is greedy, it will attempt to match the greatest possible number of repeats of the current token. ".+" matches "def" "ghi" in abc "def" "ghi" jkl
+? "lazy plus" Repeats the token one or more times. This repeat is lazy, it will attempt to match the fewest possible number of repeats in the current token. ".+?" matches "def" in abc "def" "ghi" jkl

Ways to specify custom repeats

{n} where n is an integer >= 1 Repeats the token exactly n times. a{3} matches aaa
{n,m} where n >= 0 and m >= n "greedy" Repeats the token between n and m times. This repeat is greedy, it will attempt to match the current token as many times as possible; up to m times. a{2,4} matches aaaa , aaa or aa
{n,m}? where n >= 0 and m >= n "lazy" Repeats the token between n and m times. This repeat is lazy, it will attempt to match the current token as few times as possible; down to n times. a{2,4}? matches aa , aaa or aaaa
{n,} where n >= 0 Repeats the token at least n times. This repeat is greedy, it will attempt to match the current token as many times as possible. a{2,} matches aaaaa in aaaaa
{n,}? where n >= 0 Repeats the token at least n times. This repeat is lazy, it will attempt to match the current token as few times as possible; down to n times. a{2,}? matches aa in aaaaa
Copyright © Solid Fluid 2007-2022
Last modified: SolFlu  Sat, 20 Jun 2009 23:07:46 GMT