How to find all divides ( / ) but not comments (//) ?

Find, replace, find in files, replace in files, regular expressions

How to find all divides ( / ) but not comments (//) ?

Postby dark3phoenix » Thu May 12, 2005 2:31 pm

This might be very simple, but I'm a beginner when it comes to regular expressions.

I've diligently read the help and the other topics, but I can't figure out how to
find all divides ( / ) in my C project, but not the //, /*, */
which may appear all over the project, including on the line which has a valid divide.

I'm willing to put up with a few mis-finds (such as in-between multiple line /*...*/ comments), but 80K+ results is too much to scan visually.

Can anyone help, please?

Thanks

cr.
dark3phoenix
 

Re: How to find all divides ( / ) but not comments (//) ?

Postby mrainey56 » Thu May 12, 2005 6:56 pm

What I would do is first replace all the //, /*, and */ pairs with characters that are sure to be absent from the text.

// to @~@
/* to @#@
*/ to @&@

or something along those lines


Then find all the single /'s and do whatever you want with them

Then reverse your original replaces


This sounds slow, but really isn't.

If you'll do it again in the future, put the commands into a macro or two.


Of course, somebody might come up with a regex to do it all. I hope so. :D
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How to find all divides ( / ) but not comments (//) ?

Postby Mofi » Fri May 13, 2005 1:38 am

Try this regular expression in Ultraedit style: [~/^*^-]/[~/^*]

It searches for a / with a preceding charachter, which is not a /, * or - (to exclude comments like pre-/post-processing) and a following character, which is not a / or *.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4051
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to find all divides ( / ) but not comments (//) ?

Postby dark3phoenix » Fri May 13, 2005 7:26 am

Thanks for the replies.

The search and replace would have worked as well, although the Regex solution was what I was searching for.

It worked great, and I learned quite a bit about how it works - I'll start using Regular Expressions more often to get practice.

Thanks again,
cradoias
dark3phoenix
 


Return to Find/Replace/Regular Expressions

cron