Preg_replace PHP AND

Is there an operator ANDfor PHP? Regex.

I am trying to replace everything with documentwith 'AND ).

$output = preg_replace('/document.*\'/', '', $output);

Any idea how this can be done?

I tried to find a tutorial for Regex, but I can not find anything good. If you have good sites or books, please give me a link. I googled a lot.

Thank.

EDIT: Misunderstanding.

This is the code before replacing.

<p>document.write(unescape('
<embed src="XXXXXX" type="application/x-shockwave-flash" wmode="window" width="712" height="475"%.35" allowFullScreen="true" ></embed>
')));</p>

I want to do this:

<p>
<embed src="XXXXXX" type="application/x-shockwave-flash" wmode="window" width="712" height="475"%.35" allowFullScreen="true" ></embed>
</p>

Replaced by:

document.write(unescape('

and

')));
+3
source share
4 answers

In fact, you want to replace the two parts and leave something in between. To prevent this from matching unwanted parts, use explicit character classes:

= preg_replace("/document[\w.(]+['](.*?)['][);]+/s", '$1', $output); 

, (' ') .

+2

OR?

["document", "'"] ["document", ")"], ? ["document", "'" OR ")"].

| "".

$output = preg_replace('/document.*(\'|\))/', '', $output);
0

AB A and B A | B A OR B

, '), .

, ', ), '|) [')]

- http://gskinner.com/RegExr/, . .

0
  • .
  • $1

$output = preg_replace("/document[^']*'([^']*)[^;]*;/", '$1', $output);

0

All Articles