![]() |
|
Problems? Is your data what you think it is? | |
PerlMonks |
bichonfrise74's scratchpadby bichonfrise74 (Vicar) |
on Oct 18, 2008 at 21:48 UTC ( #717987=scratchpad: print w/replies, xml ) | Need Help?? |
Dereferencing Syntax
* – The curly brackets around $ar, $hr and $cr are optional. I got this from the scratchpad of ikegami which I think is really useful. Regex Summary
Non-greediness For Quantifiers Syntax: (pattern)+? (pattern)*? The metacharacters + and * are greedy by default and will try to match as much as possible of the referenced string (while still achieving a full pattern match). This 'greedy' behavior can be turned off by placing a ? immediately after the respective metacharacter. A non-greedy match finds the minimum number of characters matching the pattern. Grouping and Alternation
| For Alternation Syntax: pattern1|pattern2 By separating two patterns with |, we can specify that a match on one or the other should be attempted. () For Grouping And Backreferences ('Capturing') Syntax: (pattern) This will group elements in pattern. If those elements are matched, a backreference is made to one of the numeric special variables ($1, $2, $3 etc.) (?:) For Non-backreferenced Grouping ('Clustering') Syntax: (?:pattern) This will group elements in pattern without making backreferences. Lookahead/behind Assertions
(?=) For Positive Lookahead Syntax: pattern1(?=pattern2) This lets us look for a match on 'pattern1 followed by pattern2', without backreferencing pattern2. (?!) For Negative Lookahead Syntax: pattern1(?!pattern2) This lets us look for a match on 'pattern1 not followed by pattern2', without backreferencing pattern2. (?<=) For Positive Lookbehind Syntax: pattern1(?<=pattern2) This lets us look for a match on 'pattern1 preceded by pattern2', without backreferencing pattern2. This only works if pattern2 is of fixed width. (?<!) For Negative Lookbehind Syntax: pattern1(?<!pattern2) This lets us look for a match on 'pattern1 not preceded by pattern2', without backreferencing pattern2. This only works if pattern2 is of fixed width. Backreference Variables
|
|