[英]Regex extract characters between two string including delimiters
I'm trying to extract the text between two characters including the delimiters, but only the text without the delimiter is returned:我试图提取包括分隔符在内的两个字符之间的文本,但只返回没有分隔符的文本:
.+(?<=\()(.*?)(?=\))
See the current regex demo .查看当前的正则表达式演示。
Example:例子:
Some text (1990) (//Divulgação)
Should return:应该返回:
(//Divulgação)
(not //Divulgação
) (//Divulgação)
(不是//Divulgação
)
You may extract those substrings between (
and )
using您可以使用以下方法提取
(
和)
之间的那些子字符串
preg_match('~.*\K\([^()]*\)~s', $s, $matches)
See the regex demo .请参阅正则表达式演示。
Details细节
.*
- any 0+ chars, as many as possible .*
- 任何 0+ 个字符,尽可能多\\K
- match reset operator that discards the text matched so far from the match buffer \\K
- 匹配重置操作符,它丢弃匹配缓冲区中到目前为止匹配的文本\\(
- a (
char \\(
- a (
字符[^()]*
- 0+ chars other than (
and )
[^()]*
- 除(
和)
之外的 0+ 个字符\\)
- a )
char. \\)
- a )
字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.