Sarath
Sarath

Reputation: 39

how to get sub-string using regex if I specify start and end including start and end

I have a string like 'String start &st This is the line > remaining'. I want a regex to find sub string starting from &st and ends with > including these like &st This is the line > I tried this

(?<=&st).*?(?=>)

But this does not include the start and end specified (Here &st and >) Any idea on this? I am using this in Visual basic.

Upvotes: 0

Views: 35

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521279

Just include the lookround content in your pattern:

(&st.*?>)

If, for some reason, you really needed to use lookarounds, you can rework what you originally had:

(?=&st).*?(?<=>)

Demo

Upvotes: 1

Related Questions