PDA

Click to See Complete Forum and Search --> : [RESOLVED] [RegEx for AS3] RegExp Code Keywords?


noahssite
May 7th, 2011, 11:35 AM
I wrote a script that acts as a syntax highlighter highlighting keywords a certain colour. My issue is that the RegExp expression I am currently using is flawed:

this|var|int|String|Object|is|in

The issue with the script is that words within words will be highlighted for example using the above expression following will occur:

var whatis:int = 0;

int is highlighted correctly however I do not want is to be highlighted. How do I make it so the above list is found with the following conditions:

It can not be part of other letters/numbers/symbols
The only symbols/characters that it can be beside are:

. : ? ( ) { } ! + - * / % ^

Basically it's a list of exceptions to what can be next to the keyword, on either side of it. How do I implement this? - What is the expression?

SambaNeko
May 11th, 2011, 12:08 PM
Something like...

\b (this|var|int|String|Object|is|in) (?!\w)

\b specifies to match a word boundary, and the (?!\w) specifies that what you matched should not be followed by another word character.

noahssite
May 11th, 2011, 09:38 PM
Thanks :check: