User Tools

Site Tools


notes:csharp:regex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:csharp:regex [2019/01/31]
leszek [Lookahead and Lookbehind in]
notes:csharp:regex [2019/01/31] (current)
leszek [Lookahead and Lookbehind in]
Line 163: Line 163:
  
  
-==== Lookahead and Lookbehind in ==== 
-Lookahead- and Lookbehind-Conditions (called "​zero-width assertions"​) look for things that go before or after the current match without including them in the match. They match a position like "​^"​ or "​\b"​ and **NEVER MATCH THE TEXT**. 
-There are four types of conditions: 
-  * Positive lookahead-condition '​(?​=re)'​ - match the position that precedes re 
-  * Negative lookahead-condition '​(?​!re)'​ - match the position that does not precede re 
-  * Positive lookbehind-condition '​(?​%%<​%%=re)'​ - match the position that follows re 
-  * Negative lookbehind-condition '​(?<​!re)'​ - match the position that does not follow re 
-Example: "HTML is a document description-language and not a programming-language or longdescription"​ 
-^ Pattern ^ Description ^ 
-| (?​%%<​%%=description-)language | matches the first "​language"​ | 
-| (?<​!description-)language | matches the second "​language"​ | 
-| \w+(?​=description) | matches "​long"​ in the third "​language"​ | 
-| \w+(?​%%<​%%=description) | matches the first "​description"​ and the "​longdescription"​ | 
-| \b\w+(?​=ing\b) | the beginning of words ending with "​ing"​ | 
-| (?​%%<​%%=\bre)\w+\b | the end of words starting with "​re"​ | 
-| (?​%%<​%%=\d)\d{3}\b | three digits at the end of a word, preceded by a digit e.g. '​000'​ in '​12000',​ but not '​123'​ in '​123'​ | 
-| (?​%%<​%%=\s)\w+(?​=\s) | alphanumeric strings bounded by whitespace; note: this example looks for both a prefix and a suffix | 
-Explanation of the \w+(?​%%<​%%=description) pattern: 
-  * 1. (?​%%<​%%=description) matches the position marked as @: "HTML is a document description@-language and not a programming-language or longdescription@"​ 
-  * 2. \w+ grabs whatever word precedes the position 
- 
-Above information comes from [[http://​www.codeproject.com/​KB/​dotnet/​regextutorial.aspx|code project]]. 
  
 ====Common Patterns==== ====Common Patterns====
notes/csharp/regex.txt ยท Last modified: 2019/01/31 by leszek