Obtain String between 2 strings (Regex?)


I have a textarea1 with bunch of code. I want to only display the string between: /xyz> and /yst
So if the code is fnhesufhesfhesufs/xyz>whateverishere/ystfnesfesufhunseuffesfsf/xyz>HiHowAreYou/yst enru eshrue sreusrseurhseurs
It should display (in textarea2):
Line 1: whateverishere
Line2: HiHowAreYou

I’ve never used Regex before… so I would need really really basic instructions, please :slight_smile:


After some research, I think it’s something like this ? maybe.

Dim rg as New RegEx
Dim myMatch as RegExMatch
if myMatch <> Nil then
Textarea2.text=myMatch.im not sure what goes here
Textarea2.text=“Text not found!”
End if

And I also think that this will only work for 1 string not multiple strings.

Almost on the right track :slight_smile:

Yes you are.

Your pattern will only work properly if there is never an end-of-line character in the text you are trying to match. The dot will not match an EOL character unless you set a certain switch. If you never expect there to be an EOL character, then it doesn’t matter.

I also removed the parens around the markers since you don’t need those captured in subgroups, and set the general Greedy option rather than using the qualifier (although there was nothing wrong with using it there, I just find it harder to read).

Try this:

Dim rg as New RegEx
rg.Options.Greedy = False
rg.Options.DotMatchAll = True

Dim myMatch as RegExMatch = rg.search(TextArea1.text)
if myMatch is nil then
  Textarea2.text="Text not found!"

  while myMatch <> Nil
    Textarea2.AppendText myMatch.SubExpressionString( 1 )
    TextArea2.AppendText EndOfLine

    myMatch = rg.Search()

end if

Perfect! :slight_smile: thank you so much! :smiley: