0

I have recently upgrade an IPB version of my forum but the quotes were not upgraded and IPS is not giving the support I need.

I need to build a regular expression do find and replace

For example this is the old forum format:

<div class="quotetop">QUOTE(Cleber__v @ Apr 14 2015, 12:25 PM) <a href="index.php?act=findpost&amp;pid=2778161">&lt;{POST_SNAPBACK}&gt; </a></div><div class="quotemain"><!--quotec--> TEXT TO BE KEPT <!--QuoteEnd--> </div><!--QuoteEEnd-->

And this is the new format it should be on:

`<div>
<blockquote class="ipsQuote" 
data-cite="Em 14/04/2015, (Cleber__v disse:" data-ipsquote="" 
data-ipsquote-timestamp="1428004301" data-ipsquote-userid="2350" 
data-ipsquote-username="Cleber__v" data-ipsquote-contapp="forums" 
data-ipsquote-contenttype="forums" data-ipsquote-contentclass="forums_Topic" 
data-ipsquote-contentid="105179" data-ipsquote-contentcommentid="2768819">
TEXT TO BE INSERTED</blockquote></div><p><span>​</span></p>`

So I need to find the content, save Username, postID (or commentid), time and text and replace it with the correct format.

I've been researching regex for about a week now with no sucess on how to make this happen

Anybody could help? Thank you

1
  • Maybe you need a xml parser. What's exactly you've done so far? Commented Sep 24, 2015 at 6:04

1 Answer 1

1

You should try for youself and give us the regex you tried, but here is a first step for you :

.*?>QUOTE\((?P<name>.*)\ \@\ (?P<date>[^\)]+).*?pid\=(?P<pid>[0-9]*).*?\<\!\-\-quotec\-\-\>(?P<text>.*?)\<\!\-\-QuoteEnd\-\-\>

See here how it works : https://regex101.com/r/dM0eG3/1 and how the match information corresponds to your need.

NB : you must remove all new line characters before applying this regex, but this is fairly easy to do in PHP or in any language you might use to create your db upgrade script.

That will extract all the relevant information from your text. Replacing these in the new format is left as an exercise for the reader.

Sign up to request clarification or add additional context in comments.

1 Comment

Will certainly do, thanks for the kickstart, thats exactly what i needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.