1

I want to match the ?si= on the end of YouTube links using Regex so that I can filter submitted links to remove the ?si= and what comes after.

I want to exclusively match that ID, and not anything that could potentially come after, such as ?t=300 to start 5 minutes into a video, a space/newline/closed parenthesis/less than symbol following a link, or anything else that could potentially come after said link.

Example:

[Check this out!](https://youtu.be/LY2xiOqi9gU?si=WzYuT7GK_IULnUPQ)

Check this video out:

<https://youtu.be/LY2xiOqi9gU?si=WzYuT7GK_IULnUPQ>

Check this out!

https://youtu.be/LY2xiOqi9gU?si=WzYuT7GK_IULnUPQ It's pretty cool.

Etc…

I'd really appreciate any help I can get on this.

2
  • 1
    Hello, for which app/engine? It's pointeless to ask without that data. Different apps utilize different engines.
    – Destroy666
    Commented Dec 28, 2023 at 21:29
  • If your regex engine supports lookbehind, use: (?<=\?si=)\w+
    – Toto
    Commented Dec 28, 2023 at 22:34

1 Answer 1

0

A simple regex would be si=([\w_]*).

The id is to be found in group match 1.

4
  • $ sed -re 's/si=([\w_]*)//g' <sed.txt indeed removes the ?si=... -portion... Now; how come the ? is included?
    – Hannu
    Commented Dec 29, 2023 at 7:04
  • Attempting the same at regex101.com - does NOT remove the ? before si. ==> regex101.com/r/7OS5Y6/1
    – Hannu
    Commented Dec 29, 2023 at 7:22
  • @Hannu: I don't understand - the group is the result, no need to remove anything.
    – harrymc
    Commented Dec 29, 2023 at 9:01
  • well, the intention was to remove ?si=--- according to OP. I don't understand how the ? before si gets caught - that is my initial comment, well - not very important.
    – Hannu
    Commented Dec 29, 2023 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .