Search code examples
regexpcre

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.

I have tried non-capturing groups without success : (?:^Your name is: ").*(?:")$

"(.*?)" Works but I don't want the double quotes to be selected


Solution

  • 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.

    regex101