Jump to content

Match text between two tags


king.oslo

Recommended Posts

The exact format of the pattern will be  dependent on what an input string would look like. You are likely to have problems with that code due to your greedy assertions. How fixed is the opening tag? I assume they don't always include UTF-8?B. Why is your closing tag attempting to match twice. Given the information provided, ignoring the actual pattern you have so far, the answer I would have given is...

 

#=\?UTF-8\?B\?(.+)?\?=#

Hello,

 

The tags will vary. They will be this in format:

 

=?charset?encoding?encoded text?=

 

 

for example "=? utf-8 ? B ? This is an example text ?=

 

Charset will be any charset

Encoding will be either capital B or Q,

Example text will vary

 

I want to strip everything, but not the example text.

 

What do you think?

 

Thanks,

Marius

[ot]

Why is your closing tag attempting to match twice.

That'll be a positive lookahead, looking for ?=[/ot]

D'oh of course it is, for some reason I thought both sets of ?= were escaped. I also didn't realise the first option was a positive look behind assertion (which in PHP PCRE cannot be a variable length unless I'm mistaken), I was obviously knocked for six by the characters used in the 'tags'. Perhaps I should take up drinking coffee in the morning?

how can I match everything apart from a sub-pattern?

 

For example, how do I strip everything everything apart from Q or B that are enclosed by ?'s ?

This example strip everything, but I want to strip everything apart from B or Q

<?php
$string = 'LotsOfLetters?B?LotsOfLetters';
$regex = '~\w+\?(B|Q)\?\w+~';
$replace = '';
?>

 

Thanks,

Marius

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.