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 1:36 am

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

Postposted on Sat Oct 22, 2005 1: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: 21281
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL

Postposted on Sat Oct 22, 2005 1:47 am

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

Postposted on Sat Oct 22, 2005 1:51 am

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

Postposted on Sat Oct 22, 2005 11: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
Grand Gerbil Poohbah
 
Posts: 3706
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Postposted on Sat Oct 22, 2005 12:11 pm

(.*?)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
Gerbil Khan
Silver subscriber
 
 
Posts: 9932
Joined: Fri Dec 27, 2002 8:51 pm
Location: Portugal (that's next to Spain)

Postposted on Sat Oct 22, 2005 5:25 pm

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

Postposted on Sat Oct 22, 2005 5: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
Gerbil Khan
Silver subscriber
 
 
Posts: 9932
Joined: Fri Dec 27, 2002 8:51 pm
Location: Portugal (that's next to Spain)

Postposted on Sat Oct 22, 2005 6:20 pm

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

Postposted on Mon Oct 24, 2005 12:46 pm

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
Gerbil Khan
Silver subscriber
 
 
Posts: 9932
Joined: Fri Dec 27, 2002 8:51 pm
Location: Portugal (that's next to Spain)

Postposted on Mon Oct 24, 2005 2:44 pm

cat filename.ext | grep -v yourwordgoeshere
Image
thegleek
Darth Gerbil
Gold subscriber
 
 
Posts: 7357
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI

Postposted on Mon Oct 24, 2005 4:44 pm

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

Postposted on Mon Oct 24, 2005 5:50 pm

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

Postposted on Mon Oct 24, 2005 5:55 pm

Hmm, this is really looking like code jockey stuff, so off to The Developer's Den it goes.
It is one of the blessings of old friends that you can afford to be stupid with them. Ralph Waldo Emerson.
Captain Ned
Global Moderator
Gold subscriber
 
 
Posts: 20099
Joined: Wed Jan 16, 2002 7:00 pm
Location: Vermont, USA

Postposted on Mon Oct 24, 2005 6:59 pm

Well, that's life :)

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

Postposted on Mon Oct 24, 2005 7:09 pm

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

Postposted on Mon Oct 24, 2005 8: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 Jedi
Gold subscriber
 
 
Posts: 1686
Joined: Tue Jan 01, 2002 7:00 pm
Location: The Colony, TX (Dallas suburb)

Postposted on Thu Nov 17, 2005 2: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 6:05 pm
Location: Los Angeles, CA


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 1 guest