标签: php regex preg-match
我正在尝试在两个特定匹配项之间获取字符串,例如两个主题标记。
我想要实现的目标:
输入:some text in front ##hi there## some text behind 输出:hi there
输入:some text in front ##hi there## some text behind
some text in front ##hi there## some text behind
输出:hi there
hi there
使用/%%(.*)%%/,会返回##hi there##。
/%%(.*)%%/
##hi there##
提前致谢
答案 0 :(得分:0)
你需要向前看并向后看。
(?<=##).*(?=##)
这将匹配hi there
https://regex101.com/r/qUR4NR/1