Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一个在 php 中使用的正则表达式,它将 rel='lightbox[nason]' 添加到找到字符串 /gallery/dsc_ 的 a 标记中。
示例输入字符串:http://myURL/gallery/dsc_8691-1-bw-3/'title='DSC_8691-1-bw'>
示例输出字符串:http://myURL/gallery/dsc_8691-1-bw-3/' title='DSC_8691-1-bw' rel='lightbox[nason]'>
像那样
$count = null; $returnValue = preg_replace('~(a.*href=(?:"|\').*/gallery/dsc_.*(?:"|\'))~U', '$1 rel="lightbox[nason]"', '<a href="http://myURL/gallery/dsc_8691-1-bw-3/" title="DSC_8691-1-bw">', -1, $count);