Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Searching for text while excluding other text
Searching for text while excluding other text [message #794951] Thu, 09 February 2012 22:31 Go to next message
Angus Mising name is currently offline Angus Mising nameFriend
Messages: 14
Registered: November 2011
Junior Member
I sometimes use regular expressions, but only about 10% of their features and most of what I want to do I can't. I don't know how to exclude certain strings from searches, only include them and exclude certain other features that aren't very versatile. How do I do that?

I need to edit a bunch of trace calls called "MyTrace". I hit over 1,000 of them. I could reduce that by filtering out lines that end in "LOGx);" where x is a 'Q', 'W', 'R' and a few other things, except 'S'. So if it ends in "LOGS);" I do want to hit on that one. Oh yeah, I could also filter out a lot of them by excluding the ones that are commented out, which is rather a lot.

If I can get a helpful answer to this, it'll sure help me for a heck of a lot of other tasks I'm going to have to perform for the rest of my career.

I'm running Eclipse for PHP Developers (among other languages) 3.0.2.
Re: Searching for text while excluding other text [message #795242 is a reply to message #794951] Fri, 10 February 2012 08:35 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
I would advise you to read something about regexp, e.g. http://www.regular-expressions.info/quickstart.html

There are also some websites where you can online test your regexp
http://www.regextester.com/
http://www.quanetic.com/Regex

Regular expressions are very powerful but it takes a steep learning curve and you have to practice it regularly.


In your case, you could try:
.MyTrace.LOGS\);$

This will show all lines that contain the string "MyTrace" and "LOGS);" followed by a line end ("$").


BTW, when you hit CTRL-Space in the Search Dialog in Eclipse (the field name "Containing text") you will get a list of possible regexp that Eclipse knows of.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Searching for text while excluding other text [message #795489 is a reply to message #795242] Fri, 10 February 2012 14:29 Go to previous messageGo to next message
Angus Mising name is currently offline Angus Mising nameFriend
Messages: 14
Registered: November 2011
Junior Member
I've been through a lot of reference material, but came to the conclusion that regular expressions don't do complex exclusions on strings. When I Googled for things like 'regular expressions "excluding the string"' I found no joy. One recommendation is that two searches are performed, with the results from the second being used to eliminate among the first results. Obviously, this guy was using regex in some sort of script and not an editor's text search feature.

So the solution would involve some kind of feature of Eclipse that can perform these exclusions outside the scope of a single regex, unless I'm wrong about the limitations of regex. Looking for what begins with "MyTrace" and ends in "LOGS);" is all very well, but I'm still faced with the problem of looking for ones that don't end in any kind of "LOGx" and also exclude ones that begin with "//MyTrace"? Maybe a plugin or some perspective I haven't found yet?
Re: Searching for text while excluding other text [message #795502 is a reply to message #795489] Fri, 10 February 2012 14:47 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Exclusion is possible.

Here from the Eclipse search dialog:

Quote:
Excluded character set

Matches a single character that is not one of the excluded characters.

Examples:
The expression "[^ecl]" matches "o" and "d" in text "cold".
The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l.


=>
.MyTrace.LOG[S&&[^QWR]]\);$


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Searching for text while excluding other text [message #795521 is a reply to message #795502] Fri, 10 February 2012 15:15 Go to previous messageGo to next message
Angus Mising name is currently offline Angus Mising nameFriend
Messages: 14
Registered: November 2011
Junior Member
That seems to have excluded everything, but
MyTrace.*LOG[S&&[^QWR]]\);$
got it. But so does
MyTrace.*LOGS\);$
for that matter. But still, the problem is complex exclusions, like phrases and such, not just character sets. Could regex be used to filter out "//MyTrace" and "/*MyTrace" and the various other variations on commenting stuff out? Can it get hits on things beginning with "MyTrace" but not ending in "LOGx);"? More importantly, can Eclipse do it?
Breaking it up into multiple searches is an acceptable option, but only w/minimal overlap. But I don't see how that can be applied here.

Let me put it this way, the pseudocode would look like:
"MyTrace" AND NOT "LOG^[QWR]" AND NOT ( "//.*MyTrace" OR "/\*.*MyTrace" )
I think that would just about get it all.

[Updated on: Fri, 10 February 2012 15:23]

Report message to a moderator

Re: Searching for text while excluding other text [message #797278 is a reply to message #795521] Mon, 13 February 2012 09:15 Go to previous message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
I think you should better ask this question in a special forum about regexp or Perl (Perl uses a lot of regexp). If you get a positve answer there you can try the expression in Eclipse.

These links might also be interesting http://www.codinghorror.com/blog/2005/10/excluding-matches-with-regular-expressions.html

http://bloggingabout.net/blogs/arjen/archive/2008/12/03/regex-exclude-lines-containing-a-specific-word.aspx


If you are successful it would be fine if you could post your solution here.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Previous Topic:Compile and Link in a specific order
Next Topic:Problems compiling HELLOWORLD ¿??¿
Goto Forum:
  


Current Time: Tue Apr 16 11:48:16 GMT 2024

Powered by FUDForum. Page generated in 0.35567 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top