1

this is my full HTML Code to find and replace:

    <figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter">
        <div class="wp-block-embed__wrapper">
            <blockquote class="twitter-tweet" data-width="550" data-dnt="true">
                <p lang="en" dir="ltr">
                    <a href="https://twitter.com/hashtag/CrisisCore?src=hash&amp;ref_src=twsrc%5Etfw">#CrisisCore</a>
                        –Final Fantasy VII– Reunion is coming to PS5, PS4, Xbox Series X|S, Xbox One, Nintendo Switch and Steam on December 13.<br><br>Here&#39;s how it&#39;ll run on each platform.
                    <a href="https:// t.co/ 2IdZP6yQGn">pic.twitter.com/2IdZP6yQGn</a>
                </p>
                &mdash; FINAL FANTASY VII (@finalfantasyvii) 
                <a href="https://twitter.com/finalfantasyvii/status/1593246579489505281?ref_src=twsrc%5Etfw">November 17, 2022</a>
            </blockquote>
            <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
        </div>
    </figure>

(Shortner URL to.co dont work in stackoverflow)

and i need only the Twitter Share URL:
https://twitter.com/finalfantasyvii/status/1593246579489505281?ref_src=twsrc%5Etfw

and now can i replace this in: [embed width="550"]$1[/embed]
but the regex need to serach the full html and replace it in the short code.

Can we say: find the class= * wp-block-embed-twitter and find the Twitter-URL (https://twitter.com/finalfantasyvii/status/1593246579489505281?ref_src=twsrc%5Etfw) and then replace it in the Short-Code?


This code changes again and again

<a href="https://twitter.com/hashtag/CrisisCore?src=hash&amp;ref_src=twsrc%5Etfw">
    #CrisisCore
</a>
–Final Fantasy VII– Reunion is coming to PS5, PS4, Xbox Series X|S, Xbox One, Nintendo Switch and Steam on December 13.<br><br>Here&#39;s how it&#39;ll run on each platform.
<a href="https:// t.co/ 2IdZP6yQGn">pic.twitter.com/2IdZP6yQGn</a>

and this code:

&mdash; FINAL FANTASY VII (@finalfantasyvii) 
<a href="https://twitter.com/finalfantasyvii/status/1593246579489505281?ref_src=twsrc%5Etfw">
    November 17, 2022
</a>

Unfortunately, I have no idea about regex at all. I have familiarized myself with a few examples from https://regex101.com/.
Is there maybe a regex generator?
Or what is the best way to handle so much code with the parser regex?

maybe someone can help me here? Or tell me where I can get help.

4
  • 1
    Does that URL contain always /status/ and ?ref_src=twsrc%5Etfw ? Commented Nov 22, 2022 at 20:11
  • if you go on twitter you can see in the "Tweet embed" the Url like this scheme: https://twitter.com/WalkingDead_AMC/status/1595099944636932097 the ?ref_src could therefore also be deleted Commented Nov 22, 2022 at 20:23
  • this is the Twitter URL + "Twitter Username" + status + "Post-ID" Commented Nov 22, 2022 at 20:25
  • And wordpress like in the Editor: [embed width="550"]https://twitter.com/WalkingDead_AMC/status/1595099944636932097[/embed] Commented Nov 22, 2022 at 20:26

1 Answer 1

1

Try:

(https:\/\/twitter\.com\/[^\/]+\/status\/\d+)\s*[^"]+

Regex demo.


(https:\/\/twitter\.com\/[^\/]+\/status\/\d+) - match http://twitter.com/<name>/status/<any number> as group 1

\s*[^"]+ - we don't want the parameters, so match until end of parameter "


The substitution is then:

\[embed width="550"\]\g<1>\[/embed\]
Sign up to request clarification or add additional context in comments.

3 Comments

the first steps is very nice, THANKS! But the other code is the "problem". search for the full html, and replace it in the simple code: \[embed width="550"\]\g<1>\[/embed\] i edit the post up.
@Sebastian But what is the problem? What language do you use?
This is an HTML Scraper. Which sees the source code of a web page.

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.