473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

matching everything but a word using ^ and preg_replace

I can't fing a way, to match any characters except the phrase 'foo'.
Using [^abc]+ matches any character except a, b or c, but I need to not
match 'foo', because f is ok, o is ok, but foo - 3 letters at once not

Any clue?

Thanks

--
Daniel Kończyk
http://konczyk.net
Jul 16 '05 #1
1 2825
In article <sl*********************@gnu.univ.gda.pl>,
Daniel KoŸczyk <dr*******@voruta.eu.0rg> wrote:
I can't fing a way, to match any characters except the phrase 'foo'.
Using [^abc]+ matches any character except a, b or c, but I need to not
match 'foo', because f is ok, o is ok, but foo - 3 letters at once not

Any clue?


If you just want to match "some pattern when not followed by 'foo'" or
"some pattern when not preceded by 'foo'", then you're looking for
lookahead or lookbehind syntax. See the section on "Assertions" in <http://us4.php.net/manual/en/pcre.pattern.syntax.php>. For instance, here's two of their examples:

*foo(?!bar)

*****matches*any*occurrence*of*"foo"**that**is**no t**followed**by
*****"bar"
*(?<!foo)bar

*****does*find*an*occurrence*of*"bar"*that**is**no t**preceded**by
*****"foo"

--
CC
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Fred | last post by:
Hi, With the sentence : "Bordeaux est au bord de l'eau" How to do to underline, for instance, the word "eau" ? without underlining the substring of "Bordeaux" ? I don't know how to isolate...
3
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str'...
8
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just...
5
by: monomaniac21 | last post by:
hi all what is the preg for capitals in a word to be replaced by that word preceded by a space? i need to be able to do this in preg: thisWord := this Word AnotherExample := Another Example
4
by: Thomas Mlynarczyk | last post by:
Hello, I have two arrays like this: $aSearch = array( 'A', 'B', 'C.D', 'E', 'F' ); $aSubject = array( 'A' =0, 'A.B' =1, 'X' =2, 'C.D.E' =3, 'A.B.C' => 4 ); Now I want to search $aSubject...
0
by: ofuuzo1 | last post by:
Hi, I am new to php. I have text files each containing some metadata. I would like to use preg_replace to remove some of the fields in each text file. Some contents of a field can go over several...
6
by: boyindie86 | last post by:
Hi I have been fighting with this lump of code for the last week what I am trying to do is that I am passing words into passages of texts, and I want the system to go and find exact word matches...
5
by: gentsquash | last post by:
In a setting where I can specify only a JS regular expression, but not the JS code that will use it, I seek a regexp component that matches a string of letters, ignoring case. E.g, for "cat" I'd...
0
by: saravanakumar muthurangan | last post by:
Hello all, i need to correct a misspelled word automatically with a most matching word by using MS word.dll in vb.net 2005, i m getting the checkspelling window with the below code but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.