Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The regex parser has an if conditional and the ability to group items into named capture groups; to which I will demonstrate. </p> <p>Here is an example where the patttern looks for symbols first (<em>only a comma add more symbols to the set [,]</em>) then numbers and drops the rest into words.</p> <pre><code>string text = @"There are 4 numbers in this string 40, 30, and 10"; string pattern = @" (?([,]) # If a comma (or other then add it) is found its a symbol (?&lt;Symbol&gt;[,]) # Then match the symbol | # else its not a symbol (?(\d+) # If a number (?&lt;Number&gt;\d+) # Then match the numbers | # else its not a number (?&lt;Word&gt;[^\s]+) # So it must be a word. ) ) "; // Ignore pattern white space allows us to comment the pattern only, does not affect // the processing of the text! Regex.Matches(text, pattern, RegexOptions.IgnorePatternWhitespace) .OfType&lt;Match&gt;() .Select (mt =&gt; { if (mt.Groups["Symbol"].Success) return "Symbol found: " + mt.Groups["Symbol"].Value; if (mt.Groups["Number"].Success) return "Number found: " + mt.Groups["Number"].Value; return "Word found: " + mt.Groups["Word"].Value; } ) .ToList() // To show the result only remove .ForEach(rs =&gt; Console.WriteLine (rs)); /* Result Word found: There Word found: are Number found: 4 Word found: numbers Word found: in Word found: this Word found: string Number found: 40 Symbol found: , Number found: 30 Symbol found: , Word found: and Number found: 10 */ </code></pre> <p>Once the regex has tokenized the resulting matches, then we us linq to extract out those tokens by identifying which named capture group has a success. In this example we get the successful capture group and project it into a string to print out for viewing.</p> <p>I discuss the regex if conditional on my blog <a href="http://omegacoder.com/?p=56" rel="nofollow">Regular Expressions and the If Conditional</a> for more information.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload