I want to match text after given string. In this case, the text for lines starting with "BookTitle" but before first space:
BookTitle:HarryPotter JK Rowling BookTitle:HungerGames Suzanne Collins Author:StephenieMeyer BookTitle:Twilight
Desired output is:
HarryPotter HungerGames
I tried: "^BookTitle(.*)"
but it's giving me matches where BookTitle: is in middle of line, and also all the stuff after white space. Anyone help?
you can have positive lookbehind
in your pattern.
(?<=BookTitle:).*?(?=\s)
For more info: Lookahead and Lookbehind Zero-Width Assertions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With