[英]How to exclude parts of a line in regex
Out of the line Your name is: "Foo Bar"
I want to select Foo Bar
in regex only.行外
Your name is: "Foo Bar"
我只想在正则表达式中使用 select Foo Bar
。
I have tried non-capturing groups without success: (?:^Your name is: ").*(?:")$
我尝试过非捕获组但没有成功:
(?:^Your name is: ").*(?:")$
"(.*?)"
Works but I don't want the double quotes to be selected "(.*?)"
有效,但我不想选择双引号
As you tagged pcre , you don't have to use a lookbehind assertion but you can match the text and then use \K
to forget what is matched so far.当您标记pcre时,您不必使用 lookbehind 断言,但您可以匹配文本,然后使用
\K
忘记到目前为止匹配的内容。
^Your name is: "\K.+(?="$)
See a regex demo .请参阅正则表达式演示。
Or without lookarounds at all and a capture group:或者根本没有环顾四周和捕获组:
^Your name is: "(.+)"$
See another regex demo .请参阅另一个正则表达式演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.