【问题标题】:Regular expression to match any tiktok video id and url匹配任何tiktok视频id和url的正则表达式
【发布时间】:2022-12-29 10:47:14
【问题描述】:

我试图用一个正则表达式匹配所有这些:

  • https://m.tiktok.com/h5/share/usr/6641141594707361797.html
  • https://m.tiktok.com/v/6749869095467945218.html
  • https://www.tiktok.com/embed/6567659045795758085
  • https://www.tiktok.com/share/user/6567659045795758085
  • https://www.tiktok.com/trending?shareId=6744531482393545985
  • https://www.tiktok.com/@burntpizza89/video/7067695578729221378?is_copy_url=1&is_from_webapp=v1
  • https://www.tiktok.com/@burntpizza89/video/is_copy_url=1&is_from_webapp=v1&item_id=7067695578729221378
  • https://vm.tiktok.com/ZMF6rgvXY/

除了最后一个,它工作正常。当前的正则表达式是:

"\bhttps?:\/\/(?:m|www|vm)\.tiktok\.com\/.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+)\b"gm

它完美地处理了所有这些数字 ID(.tiktok.com/@burntpizza89/video/7067695578​​729221378),但我还需要以某种方式匹配这些类型的链接,其中包含一些特定的 url (.tiktok.com/ZMF6rgvXY/) with just one regex. So for the match I would get or digit-only id, or the url which contains digits and characters.

【问题讨论】:

标签: node.js regex url


【解决方案1】:

尝试最后一部分:

~https?://(?:www.)?tiktok.com/S*/video/(d+)|https?://(?:www.)?vm.tiktok.com/S*/~

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    相关资源
    最近更新 更多