Tags:
create new tag
view all tags

How can I stop search for a fixed string finding the page that the search is on?

I have a search like %SEARCH{"Made by Cirrus"} to make a list of all the parts made by Cirrus. However, the search also shows up the page containing itself. Is there a way to stop this from happening? .

  • TWiki version: 01 Sep 2001 Release
  • Web server: apache
  • Server OS: Linux Mandrake 8.1
  • Web browser: Opera
  • Client OS: Win98

-- EliotBlennerhassett - 23 Jul 2002

Answer

You can use the traditional hack: quote a letter in a regex search to avoid finding onself, in your case: (end % omitted for quoting)

%SEARCH{"[M]ade by Cirrus", regex="on"}

-- ColasNahaboo - 23 Jul 2002

Perl/TWiki Newbie Comment: Ok, I finally see (again) why that works, but only for a search in body text (scope="text"), not for a page name search (scope="topic").

The reason it works is that:

  • It does match any string like "Made by Cirrus" (this is the desired behavior)
  • In the particular body text that you don't want to be included, it won't find the string "Made by Cirrus", it will only find the string "[M]ade by Cirrus" which will not be matched by the pattern "[M]ade by Cirrus".

The reason it doesn't help for a page name is that you could not, and most likely would not attempt to, make a page name like "[M]ade by CirrusBlahBlahBlah". (Even if you could include spaces in the name.)

-- Main.RandyKramer - 24 Jul 2002

mmm. I dont understand your concern. Since the SEARCH is in the body of topics, it will not be found anyways when searching topics names? Or did you mean something else?

PS: this is not a perl hack. I use it daily to find processes, e.g: ps xw|grep '[m]ozilla'
-- ColasNahaboo - 29 Jul 2002

You are right, but if the search was for page names, and the page name was MadeByCirrus, you would not (and AFAIK could not) rename the page to [M]adeByCirrus. I'm not sure I'm being clear -- suppose I had page names like the following:

  • MadeByCirrus
  • MadeByCirrusIntroduction
  • MadeByCirrusTestTopic
  • MadeByCirrusConclusion

And, on MadeByCirrus I wanted an inline search of page names that found all but MadeByCirrus. AFAIK, I could not do it by renaming that page to [M]adeByCirrus (and, even if I could, I'm not sure I would).

In my particular case, I tried adding "toc" in lower case to make the first page the equivalent of MadeByCirrustoc and then did a search for ^MadeByCirrus[^a-z] which, for some reason, still found MadeByCirrustoc. (That is a made up example. In the real situation I searched for the equivalent of ^MadeByCirrus[^t] and it worked -- I don't know why the [^t] worked and the [^a-z] did not.) (Oops, maybe I do see (or see a glimmer) -- I may have needed to use [^a-z]+ -- I'll try that next time I get a chance.) - [[Main.RandyKramer#30_Jul_2002][rhk]

-- RandyKramer - 29 Jul 2002

For the topic name case, the solution is easy - just search for MadeByCirrus[A-Za-z0-9]+ - this requires at least one letter after the initial part. You could also do MadeByCirrus\w+ which allows '_' as well.

Example: Searched: ^SearchF\w+", scope="topic", regex="on

Results from Support web retrieved at 09:21 (GMT)

How can I stop search for a fixed string finding the page that the search is on? I have a search like `Made by Cirrus`} to make a list of all the parts made by Cirrus...
Number of topics: 1

-- RichardDonkin - 30 Jul 2002

Thanks, that's very helpful!

Now, since we're turning this into a tutorial on regular expression searches wink (which is great, AFAIC)...

I just realized that a more specific exclusion in the case above (where I want to exclude MadeByCirrustoc) would be something like:

^MadeByCirrus(?!toc)

But I'm not sure of the exact syntax -- I may do some experimenting with this the next time the occasion arises unless somebody corrects it here. Fixed to use proper negative lookahead. -- WalterMundt

The advantage of this revised search would be that I could change the page name to MadeByCirrusToc which is more readable and less likely to exclude some other page by accident (like one named MadeByCirrusTocDumbPageName). (The corresponding search would be something like: ^MadeByCirrus^(Toc), but I make no guarantees.)

I left the status as AnsweredQuestions as I believe the original question has been answered.

-- RandyKramer - 30 Jul 2002


I am reopening this question with a variation: in topic JavaLanguage I want a search for all topics beginning with Java ("^Java") except for the current topic, JavaLanguage. The above tricks work to exclude a topic name only when it is the prefix of the topics you want (something I do fairly often). The problem here is a little tougher. I want to match, e.g., JavaEditors, JavaLanguageDocumentation, JavaTips, etc., but not JavaLanguage. Suggestions? (Need solution for Dec2001 release, but would be interested in hearing about features in the current release that make this easier or even possible. I think what I need would best be described as a "but not" operator, which in logic would be expressed as "and not".)

-- MitchellModel - 18 Feb 2003

You need to read up on the man page for your grep, probably GNU grep. However, I don't think any greps support what you need, which is negation of a regex element, not just a character class. This could be done in Perl but you'd need a Perl equivalent of grep (may be done already - there's an effort to write Unix tools in Perl, try Google:perl+power+tools).

-- RichardDonkin - 18 Feb 2003

^Java(?!Language$)

Oh, and man perlre is a nice Perl regex manpage on most Unix systems. Just skip down to the first header if you're only worried about them for searching, the first section is about using them in Perl code.

-- WalterMundt - 19 Feb 2003

I tired searching on "^Java(?!Language$)" with regex=on but got nothing. Searching on ^Java" returns a bunch of pages, including JavaLanguage. Did I misunderstand?

-- MitchellModel - 16 Apr 2003

man grep is the important one - searching in TWiki is done using grep, not Perl, so man perlre may confuse the issue.

-- RichardDonkin - 16 Apr 2003

TWiki has now an excludetopic="" parameter. See TWikiVariables for more.

-- PeterThoeny - 01 Nov 2003

Edit | Attach | Watch | Print version | History: r13 < r12 < r11 < r10 < r9 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r13 - 2003-11-01 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.