Reply To: Need RegEx help!

Product Compare Forums Multi-Edit Support Need RegEx help! Reply To: Need RegEx help!


The easiest way would be to switch to Perl-style regexes and use the word-boundary anchors. Of course, to avoid matching within strings or comments, you’ll need to either explicitly rig the expression so it doesn’t match in those conditions, or write a macro something like the following:[code:c3vrpxoy]while(sCurrentWord != "") {
while(Find_Text(’([^A-Za-z0-9])’ + sCurrentWord + ‘([^A-Za-z0-9])’, 0, _RegExp)) {
int nCursorStatus = GetStatusAtCursor();
if(nCursorStatus & (_gsac_Comments | _gsac_String))
Replace(” + sCurrentWord + ‘\1’);
call GetNextKeyword;
}[/code:c3vrpxoy]The other keywords beginning with “_gsac_” are defined in the system macro source file With them you can test to see whether the cursor is currently on any of the syntactically different kinds of text Multi-Edit recognizes.

Incidentally if you look at the regex string in the call to Find_Text() above, you’ll see one way of marking word boundaries without resorting to Perl regexes (although they really are much more powerful).

Another thing I would note is that the easiest way to prevent the assembler-style comments you show in your sample text from being considered is simply to not put any semi-colons in your character classes (unless they’re negative classes). It probably should go without saying that the dot operator is a no-no in instances where you’re trying to do something like that, as well, since it will match anything. It’s especially insidious coupled with the Kleene star, since then it can match any amount (or none at all) of anything. Dangerous, and often not what you want, but people are in the habit of tossing off .* without thinking.

And a Parthian shot: instead of disallowing only those characters that can occur in a hexadecimal number in the class preceding the number, disallow anything that could form part of a legal word in the language you’re using. And as I always do, I recommend acquiring and reading carefully “Mastering Regular Expressions” from <a href="]O’Reilly Books[/url:c3vrpxoy”>. It’s not a cookbook, but will get you into the guts of how and why regular expression engines work the way they do, which is far more valuable.