Forum Moderators: coopster
[zend.com...]
which links to this place
[snowball.tartarus.org...]
there's a script at the bottom, might be worthwhile!
The example has nothing to do with what I need. I have several instances of where this type of regexp needs to be implemented. I was just trying to give a general description of the question behind the regexp...
So, ignoring the language aspects...
Say that I have this string instead:
foo bar widget blah blouh bleh bla
I want to add "et" to the end of each word, unless the word already ends with "et" or is "foo" or "bar".
How do I match which words should get the "et"?
I want to add "et" to the end of each word, unless the word already ends with "et" or is "foo" or "bar".
substr can be used to match the ending characters, or a preg_match/replace maybe?
1) iterate through the words
2) if (substr($word,-2,2)!= 'et'&$word!= 'foo'&$word!= 'bar')
{ $word .= 'et'; }
too slow...
My own preg_replace doesn't work since it replaces whatever the last character is with "et"... (or so I assume, since I haven't tested it yet)
If possible, I'd like to do it with a preg_replace. That way I can do it on long strings. I'm just not sure what the actual preg_replace would look like :(
I guess if you need to make sure that its not "foo" or "bar" and need to make sure the word doesnt end in 'et' there's not much point of doing a preg_replace. So instead you just put the 'et' in at the end of the string. I'm no PHP expert though ;o)