Out of the line Your name is: "Foo Bar"
I want to select Foo Bar
in regex only.
I have tried non-capturing groups without success: (?:^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.
^Your name is: "\K.+(?="$)
See a regex demo .
Or without lookarounds at all and a capture group:
^Your name is: "(.+)"$
See another regex demo .
You can use lookbehind
and lookahead
:
(?<=^Your name is: ").+(?="$)
(?<=
looks behind for Your name is: "
and (?=
looks ahead for "
.
The result will be whatever is between that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.