如何匹配iframe文本,然后在WordPress中跳过并匹配另一个字符串



我有这个 iframe 代码,我想匹配字符串开头的两个文本,并继续使用代码来查找"soundcloud">文本:

<iframe src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/297769462&amp;color=%23ff5500&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;show_teaser=true" width="100%" height="166" frameborder="no" scrolling="no"></iframe>

我的正则表达式是: (<iframe.*?></iframe>) ,它试图匹配 iframe 和介于两者之间的任何内容。

我想要的是 + 跳过两者之间的所有内容,直到它找到声音云。 如果两个条件都满足,则匹配。

任何帮助都会很棒,谢谢。

试试这个

(?i)<iframe(?=((?:[^>"']|"[^"]*"|'[^']*')*?s(srcs*=s*(['"])(?:(?!3)[Ss])*?soundcloud(?:(?!3)[Ss])*3)(?:"[Ss]*?"|'[Ss]*?'|[^>]*?)+>))1s*</iframes*>

https://regex101.com/r/KkJH6x/1

格式 化

 (?i)                              # Case insensitive modifier
 < iframe                          # The iframe tag
 (?=                               # Asserttion (a pseudo atomic group)
      (                                 # (1 start)
           (?: [^>"'] | " [^"]* " | ' [^']* ' )*?
           s 
           (                                 # (2 start), src  attribute with 'soundcloud' in value
                src s* = s* 
                ( ['"] )                          # (3), Quote
                (?:
                     (?! 3 )
                     [Ss] 
                )*?
                soundcloud                        # 'Soundcloud'
                (?:
                     (?! 3 )
                     [Ss] 
                )*
                3                                # Close quote
           )                                 # (2 end)
           # The remainder of the tag parts
           (?: " [Ss]*? " | ' [Ss]*? ' | [^>]*? )+
           > 
      )                                 # (1 end)
 )
 1 
 s* 
 </iframe s* >

相关内容

最新更新