0

We have use the following Regex function to highlight the string and numeric

String Regex function

public string StringRegEx
{
    get { return @"@?""""|@?"".*?(?!\\).""|''|'.*?(?!\\).'"; }
}

Numeric Regex function

public string NumberRegEX
{
    get { return @"[0-9].*?(?=:[0-9]*)?"; }
}

while using this regex function we have face some issues for highlighting string contains numeric

p1 = 1
p2 = 0.2

enter image description here

In this example, 1 and 2 in p1 and p2 also highlighted. How to skip the number highlighted along with the string?

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Uthistran Selvaraj
  • 1,371
  • 1
  • 12
  • 31
  • Your string regex contains `.` which matches all.You can use `[A-Za-z]` – vks Oct 14 '14 at 07:04
  • 1
    p1 and p2 are not matched by the first regex (which is used to match string literal - it is bugged, though). It is only matched by the second regex. Your regex are very poor, btw. – nhahtdh Oct 14 '14 at 07:14

1 Answers1

0

For a more general approach on how to properly catch things when dealing with a programming language snippet, take a look here.

Your problem might not be "comments in strings, strings in comments" but it is similar, namely "letters in a string that started with a number, numbers in a string that started with a letter" so you'll need a similar approach with pipe-separated regexes for the different matches you wanna have.

A more thorough explanation of this design-pattern is given here.

Community
  • 1
  • 1
asontu
  • 4,548
  • 1
  • 21
  • 29