Excluding a Whole Word with Regular Expression

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

Excluding a Whole Word with Regular Expression

Postposted on Sat Oct 22, 2005 12:36 am

Last edited by gratuitous on Thu Dec 15, 2005 12:09 pm, edited 2 times in total.
gratuitous
Gerbil Team Leader
 
Posts: 231
Joined: Fri Jan 28, 2005 2:05 pm

Postposted on Sat Oct 22, 2005 12:44 am

Do you mean like a google search? Then it would just be "-fox" however, that's too easy, so I guess I don't understand the question.
Usacomp2k3
Gerbil God
 
Posts: 20893
Joined: Thu Apr 01, 2004 3:53 pm
Location: Orlando, FL

Postposted on Sat Oct 22, 2005 12:47 am

Last edited by gratuitous on Thu Dec 15, 2005 12:09 pm, edited 1 time in total.
gratuitous
Gerbil Team Leader
 
Posts: 231
Joined: Fri Jan 28, 2005 2:05 pm

Postposted on Sat Oct 22, 2005 12:51 am

:o Quite a bit over my head then. Good luck 8)
Usacomp2k3
Gerbil God
 
Posts: 20893
Joined: Thu Apr 01, 2004 3:53 pm
Location: Orlando, FL

Postposted on Sat Oct 22, 2005 10:54 am

Probably do better in Developer's Den.

If you can call out to grep then do it as a "grep -v" that's probably the easiest way.
notfred
Minister of Gerbil Affairs
 
Posts: 2628
Joined: Tue Aug 10, 2004 9:10 am
Location: Ottawa, Canada

Postposted on Sat Oct 22, 2005 11:11 am

(.*?)dog(.*)

This you capture everything before "dog" and after "dog", essentialy giving you the same result. I presume you're using this inside some sort of program for text search/matching.
morphine
Darth Gerbil
 
Posts: 7146
Joined: Fri Dec 27, 2002 7:51 pm
Location: Portugal (that's next to Spain)

Postposted on Sat Oct 22, 2005 4:25 pm

Last edited by gratuitous on Thu Dec 15, 2005 12:10 pm, edited 1 time in total.
gratuitous
Gerbil Team Leader
 
Posts: 231
Joined: Fri Jan 28, 2005 2:05 pm

Postposted on Sat Oct 22, 2005 4:55 pm

The given regular expression was meant to be used in some sort of program (it's a Perl-compatible regular expression, although this particular case is not Perl-specific).

If you're looking for a usenet post in some page, then I'm betting that page has some sort of specific form of regexp query, which is useless for us trying to guess what it is :)

What's the specific site?
morphine
Darth Gerbil
 
Posts: 7146
Joined: Fri Dec 27, 2002 7:51 pm
Location: Portugal (that's next to Spain)

Postposted on Sat Oct 22, 2005 5:20 pm

Last edited by gratuitous on Thu Dec 15, 2005 12:11 pm, edited 1 time in total.
gratuitous
Gerbil Team Leader
 
Posts: 231
Joined: Fri Jan 28, 2005 2:05 pm

Postposted on Mon Oct 24, 2005 11:46 am

Someone named Jeff on ICQ left this to me, so I thought I'd share it with you (maybe Jeff is the poster, I don't know :) )

In answer to this thread that
you posted in:

viewtopic.php?t=34782

Here is the regex that solves the problem:

http://www.codinghorror.com/blog/archives/000425.html

Could you post it in the thread?

Thanks,

Jeff
morphine
Darth Gerbil
 
Posts: 7146
Joined: Fri Dec 27, 2002 7:51 pm
Location: Portugal (that's next to Spain)

Postposted on Mon Oct 24, 2005 1:44 pm

cat filename.ext | grep -v yourwordgoeshere
Image
thegleek
Emperor Gerbilius I
 
Posts: 6108
Joined: Tue Jun 10, 2003 10:06 am
Location: Detroit, MI

Postposted on Mon Oct 24, 2005 3:44 pm

Last edited by gratuitous on Thu Dec 15, 2005 12:11 pm, edited 1 time in total.
gratuitous
Gerbil Team Leader
 
Posts: 231
Joined: Fri Jan 28, 2005 2:05 pm

Postposted on Mon Oct 24, 2005 4:50 pm

Just code your own usenet reader...
JavaDog
Minister of Gerbil Affairs
 
Posts: 2815
Joined: Wed May 07, 2003 10:20 am

Postposted on Mon Oct 24, 2005 4:55 pm

Hmm, this is really looking like code jockey stuff, so off to The Developer's Den it goes.
Imbibo Ergo Sum
Captain Ned
Gerbilus Supremus
 
Posts: 12204
Joined: Wed Jan 16, 2002 6:00 pm
Location: Vermont, USA

Postposted on Mon Oct 24, 2005 5:59 pm

Well, that's life :)

But yeah, you should use your own usenet reader instead of a third-party solution.
morphine
Darth Gerbil
 
Posts: 7146
Joined: Fri Dec 27, 2002 7:51 pm
Location: Portugal (that's next to Spain)

Postposted on Mon Oct 24, 2005 6:09 pm

Last edited by gratuitous on Thu Dec 15, 2005 12:12 pm, edited 1 time in total.
gratuitous
Gerbil Team Leader
 
Posts: 231
Joined: Fri Jan 28, 2005 2:05 pm

Postposted on Mon Oct 24, 2005 7:28 pm

The perlish regexp would be:

Code: Select all
$string="The quick brown fox jumped over the lazy dog.";
$search="fox"
$string=~s/\s$search(\s)/$1/g;


If will search for the search term surrounded by a whitespace character and strip it out. The parens around the second whitespace save it and it is actually used as the replacement source. This keeps you from getting "brownjumped" by removing both whitespace elements. You should actually extend it to take into account it being the first in the sentance or being followed by punctuation or stuff.

--SS
SecretSquirrel
Gerbil Elite
 
Posts: 920
Joined: Tue Jan 01, 2002 6:00 pm
Location: The Colony, TX (Dallas suburb)

Postposted on Thu Nov 17, 2005 1:41 am

the standard way of specifying a "word" regex is
Code: Select all
\<fox\>

(it will match "fox" surrounded by spaces, punctuation, etc)
.. now all you need is a way to negate that which unfortunately isn't so standardized.. does the webform page you're using this in have a manual?
jimveta
Gerbil In Training
 
Posts: 3
Joined: Fri Jan 28, 2005 5:05 pm
Location: Los Angeles, CA


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 0 guests