0

No, this is not a replicate of The ':' character, hexadecimal value 0x3A, cannot be included in a name

I have a Regex for my syntax highlighter for my scripting language:

`@"\bClass+(?<range>\w+?)\b"` 

which basically marks Class Name

(with the engine I got online)

I'm no master in Regex but for some reason the : character that uses my language to create labels - doesn't work.

I tried

 @"\b:+(?<range>\w+?)\b"`, `@"\b\:+(?<range>\w+?)\b"`<RB> `@"\b(\x3A)+(?<range>\w+?)\b"

And it refuses to work!

Any ideas?

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
Mark Segal
  • 5,427
  • 4
  • 31
  • 69
  • [This is a great tool to test out RegEx sequences on-the-fly.](http://gskinner.com/RegExr/) I use it all the time. Perhaps it'll help you solve your problem. :) – qJake Jul 29 '11 at 20:50

1 Answers1

3

I suspect the issue in your case is not the : itself, but the \b before it. \b marks the boundary between a word character and nonword character, but while Class is comprised of word characters, : is a nonword character. So \b is behaving differently for : than it would for Class, so:

`\bClass` matches " Class Name"
`\b:` does not match " : Name"

If you use your original expression but replace the first \b with (?<!\w), it may identify the : properly.

drf
  • 8,461
  • 32
  • 50