Home > database >  How to exclude parts of a line in regex
How to exclude parts of a line in regex

Time:12-08

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

CodePudding user response:

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

  • Related