Resource icon

Post Content Find / Replace 2.0.1

No permission to download
This should be youtu ;)
Oh, bad, bad, typo... I will change it.

Something is wrong with step 3. It is returning results with one letter like this:
[MEDIA=youtube]Q[/MEDIA]
Just pu it in the regextester.com and look whats wrong. I try it again with the test-strings from above and step 3 works for me.
Things you should control (with regestester.com)
  • do you use the right one replacement? The number after the $ changed in my replacement strings - take a look at that
  • if that is realy OK, put my step 3 regex code (without # at the begining and #siU at the end !!) in the https://regextester.com,
    Code:
    (https?|\[url\]https?|\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\[\/url\]|\[\/URL\]|)

    Cklick at "flags" right above the regex input field and control, multiline and global are selected.

    put these test-strings in the test string text field:
    Code:
    https://www.youtube.com/watch?v=xxxxxxxxxxx[url]https://www.youtube.com/watch?v=xxxxxxxxxxx[/url]
    [URL]https://www.youtube.com/watch?v=xxxxxxxxxxx[/URL]
    https://youtu.be/xxxxxxxxxxx
    [url]https://youtu.be/xxxxxxxxxxx[/url]
    [URL]https://youtu.be/xxxxxxxxxxx[/URL]
    https://www.youtube.com/watch?v=xxxxxxxxxxx

    When you now mouse over the test-strings, a overlay should open with more info like this:
    1628887189283.webp

    As you can see then, we need group #3 (the video IDs)

    and use these replace string in subtitition field:
    Code:
    [media=youtube]$3[/media]

    The $3 means that at this place comes that what our matchesfound at group #3 short bevore.

    then you also should become such a example replacements:
    1628886942021.webp

    xxxxx stands symbolic fore your video-ID

    If so - the regex work, go back to the find posting and replace tool at your Xenforo und try a new test run. Dont forgett to add now the # at beginning and the #siU at the end of the regex when you copy it to Xenforo.
    If not - make certain screenshots out of your regextester.com so I can see the overlay open and all other input fields. :)
 
I'm about to give up 😭
Now I get this
ErrorException: [E_WARNING] preg_match_all(): Unknown modifier '(' in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
XF::handlePhpError()
preg_match_all() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 41
XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 350
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 257
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 113
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 55
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2344
XF\App->run() in src/XF.php at line 512
XF::runApp() in admin.php at line 13
 
Read carefull what i wrote...

FIRST: what was with regextester.com ? Errors? Or do it run as it should run?

Then - control your regex at missing # and #siU.
regex for regextester.com:
Code:
(https?|\[url\]https?|\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\[\/url\]|\[\/URL\]|)

same with # and #siU as regex for Xenforo:
Code:
#(https?|\[url\]https?|\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\[\/url\]|\[\/URL\]|)#siU

Do you see it? I think its an copy and paste problem... ;)

If you realy dont can run it, send me account data so I can take a look direct at your forum. Otherways we discuss the next days... and doesnt go forward. :) ;)
 
Pasting correctly:
Code:
#(https?|\[url\]https?|\[URL\]https?)(:\/\/www\.youtube\.com\/watch\?v=|:\/\/youtu\.be\/)([a-zA-Z0-9-_]+)(\[\/url\]|\[\/URL\]|)#siU

[MEDIA=youtube]$3[/MEDIA]

and

test1.webp
test2.webp

FIRST: what was with regextester.com ? Errors? Or do it run as it should run?
Sorry I tried that site, but don't know how to use it.
 
Last edited:
Ok, I see whats going up:
1628924088239.png

Thats simply a not complete video-ID match - I think your links are others then the hand full I have to test with regextester.

To look whats going wrong, I need The komplete links from post #5153, #9114, #9594 and #13132 so I can take a look why it is not match the correct way. I think its not a big trouble and fast to fix. :)


How to use regextester.com
1628924893155.webp 1628925261998.webp 1628925888511.webp

Damn - look complicated, but it isnt. :D ;)
 
Last edited:
Can anyone help change these to MEDIA=youtube bb code?

Code:
https://www.youtube.com/watch?v=xxxxxxxxxxx

https://youtu.be/xxxxxxxxxxx

(both those are plain text, no bb code)

and:

[URL="https://youtu.be/xxxxxxxxxxx"]https://youtu.be/xxxxxxxxxxx[/URL]

I ran steps 1 and 2 from @otto and they worked for those instances, these are the ones I have left but his steps he has been trying to help me with are not working.
 
Sorry, but you don't seem to really understand how the tool (serach and replace) works and so you make it almost impossible for me to help you ... :(

If the quick search for:
Code:
//youtube.com/watch?v=
can only find 2 posts, then there are only 2 posts with this search term!

This is not only the fault of my regex code, but that you provide information that is apparently not quite correct.


What happens if you try to shorten the quick search?
e.g .:
Code:
: //youtube.com
or even just
Code:
: // youtu

Does the quick search now find only 2 posts? Or more?


The regex code from me can only be used on posts that the quick search of the Serach and Replace tool found!
If the quick search can only find 2 posts, then there are only 2 posts that contain the search term of the quick search.

I asked you to give me the complete links from the posts that the quick search finds, but where the regex match fails. Did you give me this - NO.

What is possible, that this is about video-ids that contain not only 0-9, a-z, A-Z as well as "-" and "_" but also other special characters. But to check that and if necessary to include it in the regex, I would have needed the complete links and I never got them from you!

my last 50 cents to your problem:
Open the two postings from the screenshot:
1629183108370.webp
copy the COMPLETE links from the editor (toggle bbcode mode) and let's see what the video links and special video ids look like.

Then I could tell you why the regex doesn't work for you. And that’s what I’ve asked you twice now!





Not only did I give you the regex codes, but I also offered to have a look at it in your forum to help solve the problem. I also asked you for the exact links from the posts where the regex failed so far. But I never got it.

But each time there are only slightly different links than previously indicated.

I asked you to test your links on regextester.com. I have described to you several times (in text and picture) how to do this very easily. And I asked you for screenshots too ...

But:
  • no link to the forum and so no possibility to look directly why my regex code is running in the tester, but not in your forum
  • no screenshots as requested
  • no serious attempt with the regex tester - I claim everyone who can use a computer should also be able to simply fill 3 text fields with given values (I gave them to you for copy and paste as text and as screenshots!) and then from Result to take a screenshot.
You want to be able to use the Post serach and replace tool but not want to do almost the same thing in the regex tester? Realy?


Sorry, but they CAN'T really help you like that. And now, after several days try to help, I no longer want to sacrifice my free time for it. It just doesn't make sense if you don't do what people ask you to do multiple times to help you.
 
RegEx search:
Code:
#(\[CQ\=)([a-zA-Z0-9]+)(\]\[\/CQ\])#siU
At this sample your random can contain a-z, A-Z and/or 0-9 but nothing others.

replace:
Leave in this case blank to remove all found blocks/groups from your posts.


If random is more as only alphanumeric, then you have to change the regex block/group at the middle like this eg:
Code:
#(\[CQ\=)([0-9a-zA-Z.:,&/]+)(\]\[\/CQ\])#siU
... you can add the things you want to search for at the middle block/group in this case.

If your random can also contain whitespace(s) eg, add a \s in the middle block/group. For backslash(es) use \\ eg.
Sample:
Code:
#(\[CQ\=)([0-9a-zA-Z.:,&/\s\\]+)(\]\[\/CQ\]\s)#siU
Here I also added a \s at the 3. block/group end to find also the whitespace at the end of our search and remove them later to so you dont have after removing a sensless double whitespace in your posts.
Thanks a lot for the advice, but all of the 3 REGEX doesn't work based on my test.
Demo attached.

View attachment Screen Recording 2021-08-17 at 7.27.41 PM.mp4


Edit, I got it now. :)

Code:
(\[CQ\=')([0-9a-zA-Z.:,&\s\\]+)('\]\[\/CQ\])
 
Last edited:
Thats why I say, try it first with regextester - regextester is your friend. :D ;)

Yes my regex cant work, with these infos:
Post content format:
Code:
[CQ=*random*][/CQ]
At your bbcodes with more complex random string. Regex can only find what you say Regex they have to find.

Congrats to your working regex code, you see its not impossible to make a own working one. :) (y)

Edit:
Ah, I see - you do one wrong step and copy the "#" and "#siU" to regextester - yes, this wont work at regextester, as you can see at my screenshot in the post you quotet:

1629207235621.webp
To only thing my code miss was the upper comma, after insert them it works:

But I found a possible little thing that you should change at the end of the regex code:
Try to ad back the "\s" at the end, to match one whitespace after your bbcode so when the bbcode is inserted inline betwen text you will not have a double whitespace there.
1629207537798.webp

1629207571630.webp

Otherwise it looks like that:
1629207608551.webp
 
Last edited:
You can also made a shorter one, shorter is often better in performance by regex. ;)
1629207742875.png

The "\w" match also all alpha-numeric and underscore characters (works prety much same as "0-9a-zA-Z") .

And also a little bit better can be this one:
1629208134747.png

Here we look for uppercase OR ( this means the | ) lowercase: CQ or cq and we put this in a own group #2 to reuse them later in our regex code with (\2). :)
 
Last edited:
Sorry, but they CAN'T really help you like that. And now, after several days try to help, I no longer want to sacrifice my free time for it.
FREE time, hey, I told you I wanted this to be a paid job and you refused my paypal offer. :) I do appreciate that you wanted to help for free. If you would have taken the money, it would have been PAID time! ;)

I'm going to try to look over all your notes and figure it out. Like I said, it's MUCH appreciated!

Paying Make It Rain GIF by Travis
 
Last edited:
I'd like to make the replacement somewhat more useful, instead of removing it completely... I'd like to convert it to tag/@/mentions instead :).
Sample old post content:
Code:
[CQ='User_101, c: 1399153, m: 413875'][/CQ]
[CQ='User_102, c: 1392392, m: 897619'][/CQ]
[CQ='User_103, c: 1392387, m: 1789649'][/CQ]
[CQ='user_104, c: 1404633, m: 642866'][/CQ]
[CQ='User 105, c: 1403625, m: 642866'][/CQ]
[CQ='User-106, c: 1403675, m: 524468'][/CQ]
[CQ='User-107, c: 1403551, m: 524468'][/CQ]

Only a-Z, 0-9, space, underscore, and hyphen in any order are allowed in the username.
c: xxxxxxx is the comment ID from old addon.
m: 123456 is the UserID

I'd like it to convert to:
Code:
@User_101
@User_102
@User_103
@user_104
@User 105
@User-106
@User-107

This seems more tricky, I'm not sure what code to use on the Replace field.
Thanks!
 
For some reason,
#([\[CQ\=']+)([\w\-\s]+)([c:\s0-9,m'\]\[\/CQ\]]+)#siU doesn't work, but
#([\[CQ\=']+)([\w\-\s]+)([c:\s0-9,m'\]\[\/CQ\]]+)#si works fine :/.
 
FREE time, ...
You don't get me right - if I had taken money, my free time would still be wasted. And your money too. ;)
If you do not respond appropriately to simple inquiries and the basics are not understood, I cannot help you properly. :(
Look at @rdn - here I can see they have understand the basics and as you can see we find working solutions at short times.

No one can replace free time with money. ;)
 
Last edited:
How to add a single space before and after the Replacement string?
\n and \t doesn't even work.

Thanks.
 
Seems I got it?
When "userxxx" will be the real usernames - than this should work in your case.

You can safely try a run at one posting - just make the fast find more concrete to find only one posting and then let the tool run.
After that control this one post and check the result.
When its positiv, you can run with more posts matching shorter faste search term to let the tool run at more posts.
 
  • Like
Reactions: rdn
How to add a single space before and after the Replacement string?
\n and \t doesn't even work.
What when you use simply a " " (whitespace) instead \n or \t ? I think \s like at the regex code will not work at replacement string - but I havent tested yet.
 
Top Bottom