Jump to content

[SOLVED] Regular Experssion


tobeyt23

Recommended Posts

I think this is correct:

 

preg_replace('/For(.+$)/', '', $string;

 

Actually, it isn't for the simple reason you have not closed off the preg_replace function. You are missing the closing ')' character. ;)

As for the pattern itself, I would go this route:

 

preg_replace('#for(.*)#i', '', $string);

 

In your case, you are looking for a For (capital F). Is this deliberate? Or do you need to find any instance of this, regardless whether it contains capital letters or not? If caps are not an issue, then I used the i modifier after my closing delimiter so that it is all case insensitive. I used the 'zero or more' quantifier (*) just in case (for some strange reason) the last characters in the string is 'for' (or any cap variation of it). Since it is a greedy quantifier by default, it will match all the way to a newline.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.