-1

I am facing issues extracting a string between two strings/pattern.

This is what I got so far: https://regex101.com/r/yuoQha/1

enter image description here

The problem I have is that I receive a way too long string with the RegEx code I have designed, because it seems that RegEx searches from backwards on?

I marked in red what I only need. How should I modify my RegEx pattern? Does Lookahead/Lookbehind have something to do with the solution? At the end it should work with VBA. Any help is highly appreciated.

smartini
  • 404
  • 6
  • 18

1 Answers1

2

Try this pattern:

OEM[]]]><[\/]Name><Value>(.*?NameValueList.*?)(?=<[\/]Value><[\/]NameValueList)

It matches exactly what is orange in your image.

FYI, the ? after the .* are to make it non-greedy. Needed to add NameValue in there since you want it to appear once in your pattern.

cybernetic.nomad
  • 6,100
  • 3
  • 18
  • 31
  • worked for me, thanks. still try to understand that logic though. why was there a down vote actually, if there are solutions to questions? did I miss something? – smartini Nov 17 '18 at 02:19
  • 2
    https://blogs.msdn.microsoft.com/ericgu/2005/08/19/are-you-greedy-or-lazy/ – CatCat Nov 17 '18 at 03:56