HELP!!! Conditional Matches?

Results 1 to 2 of 2

Thread: HELP!!! Conditional Matches?

  1. #1
    Join Date
    Dec 1969

    Default HELP!!! Conditional Matches?

    Hi, Im a newbie with regular expression...<BR><BR>IM trying to match keywords in a color code method.<BR><BR>The regex im using now is...<BR> (If&#124Then)s<BR><BR>This works great, BUT how can i make it not match stuff after a single quote?<BR><BR>like this...<BR><BR>If e.KeyChar.IsDigit(e.KeyChar) Then &#039;If its a Digit then its ok<BR><BR>It should match the first "If" and first "Then" but not the second "If" or "Then" cause its after the single quote<BR><BR><BR>I am doing this line by line.<BR><BR>Is it posable?

  2. #2
    Join Date
    Dec 1969

    Default RE: HELP!!! Conditional Matches?

    I don&#039;t know VBScript so I&#039;ll give you an outline on how to build the regex for JScript. <BR><BR>Two other things you may have to worry about are regular expressions in your source like rx = /(?:If&#124Then)/g; <BR>and comments containing "If" and "Then". If these are also a concern let me know and I&#039;ll add more to the following regular expression.<BR><BR>The regex consists of alternative groups, the left most deal with double and single quoted string literals and are evaluated before the keywords grouping.<BR><BR>First grouping is for double qouted strings and allows them to have escaped characters.<BR><BR> "(?:[^"\]+&#124\.)*"<BR><BR>The second is for single qouted strings.<BR><BR> &#039;(?:[^&#039;\]+&#124\.)*&#039;<BR><BR>The last is for your two keywords and used a capturing parenthesis.<BR><BR> (If&#124Then)<BR><BR>Putting it all together.<BR><BR> rx = /"(?:[^"\]+&#124\.)*"&#124&#039;(?:[^&#039;\]+&#124\.)*&#039;&#124(If&#124Then)/;<BR><BR>When found, keywords should be in the second item, $[1], of the returned array $. You test for that and skip the string literal matches.<BR><BR> if (($ = rx.exec(line))[1]) alert(&#039;Found keyword&#039;);<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts