How to select a whole word inside Positve Lookbehind scope in Regex

How to select a whole word inside Positve Lookbehind scope in Regex

For eg:- (?<=BILL TO SHIP TO INVOICE TOTAL\nNetflix\s)\w+\s\w+

In above Regex expression example, to make it more generic i need to write expression instead of specific word “Netflix”

So how to write it…?

@Bhavesh_Batra

You can do like this

“(?<=BILL TO SHIP TO INVOICE TOTAL\n” + variableName + “\s)\w+\s\w+”

Hope this helps

Cheers

Sir, my question was instead of “Netlix”, it could be any word so how do i select that word

using a variable won’t help as i don’t have any pre-assigned value.

@Bhavesh_Batra

Then try this

(?<=BILL TO SHIP TO INVOICE TOTAL\n[A-Za-z]+\s)\w+\s\w+

Cheers

It is showing an error on + quantifier

" + A quantifier inside a lookbehind makes it non-fixed width "

@Bhavesh_Batra

Where are you using it can you show please

Cheers

I want to Extract Aman Basra from this string, but i want to make generic so that any name would be extracted

@Bhavesh_Batra

Please select .net flavour then the error would be gone

Cheers

1 Like

keep in mind windows linebreak \r\n so we do use defensive \r?\n for this

1 Like

@Anil_G
Thanks Alot :v:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.