views:

118

answers:

1

Im new to Preg Replace and Ive been trying to get this to work, i couldn't so StackOverflow is my last chance.

I have a string with afew of these

('pm_IDHERE', 'NameHere');">

I want it to be replaced with nothing, so it would require 2 wildcards for NameHere and pm_IDHERE

but ive tried it and failed myself, so could someone give me the right code please, and thanks :)

+3  A: 

Update:

You are almost there, you just have to make the replacement an empty string and escape the parenthesis properly, otherwise they will be treated as capture group (which you don't need btw):

$str = preg_replace("#\('pm_.+?', '.*?'\);#si", "", $str);

You probably also don't need the modifiers s and i but that is up to you.


Old answer:

Probably str_replace() is sufficient:

$str = "Some string that contains pm_IDHERE and NameHere";
$str = str_replace(array('pm_IDHERE', 'NameHere'), '', $str);

If this is not what you mean and pm_IDHERE is actually something like pm_1564 then yes, you probably need regular expressions for that. But if NameHere has no actual pattern or structure, you cannot replace it with regular expression.
And you definitely have to explain better what kind of string you have and what kind of string you have want to replace.

Felix Kling