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\?(.+)?\?=#

Link to comment
Share on other sites

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

Link to comment
Share on other sites

[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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.