Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:19:38+00:00 2026-05-26T00:19:38+00:00

I can only seem to find help for PHP on this subject so am

  • 0

I can only seem to find help for PHP on this subject so am opening a new question!

I have written a function to get a string between 2 other strings but at the moment it is still returning the first part of the string and simply removing anything after the EndSearch value:

Public Function GetStringBetween(ByVal Haystack As String, ByVal StartSearch As String, ByVal EndSearch As String) As String
    If InStr(Haystack, StartSearch) < 1 Then Return False
    Dim rx As New Regex("(?=" & StartSearch & ").+(?=" & EndSearch & ")")
    Return (rx.Match(Haystack).Value)
End Function

Demo Usage:

Dim Haystack As String = "hello find me world"
    Dim StartSearch As String = "hello"
    Dim EndSearch As String = "world"
    Dim Content As String = GetStringBetween(Haystack, StartSearch, EndSearch)
    MessageBox.Show(Content)

Returns: hello find me

Also, in PHP I have the following function:

function get_all_strings_between($string, $start, $end){
preg_match_all( "/$start(.*)$end/U", $string, $match );
return $match[1];
}

Is there a similar function in VB.NET for preg_match_all?

Example Function (Non-Functional Due To Returning m.Groups):

Public Function GetStringBetween(ByVal Haystack As String, ByVal StartSearch As String, ByVal EndSearch As String, Optional ByVal Multiple As Boolean = False) As String
        Dim rx As New Regex(StartSearch & "(.+?)" & EndSearch)
        Dim m As Match = rx.Match(Haystack)
        If m.Success Then
            If Multiple = True Then
                Return m.Groups
            Else
                Return m.Groups(1).ToString()
            End If
        Else
            Return False
        End If
    End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:19:39+00:00Added an answer on May 26, 2026 at 12:19 am

    I don’t understand why you are using lookahead:

    Dim rx As New Regex("(?=" & StartSearch & ").+(?=" & EndSearch & ")")
    

    If StartSearch = hello and EndSearch = world, this generates:

    (?=hello).+(?=world)
    

    Which, matched against the string, finds and returns exactly what it’s supposed to. Build something like:

    Dim rx As New Regex(StartSearch & "(.+?)" & EndSearch)
    Dim m As Match = rx.Match(Haystack)
    If m.Success Then
        Return m.Groups(1).ToString()
    
    ' etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation that I can't seem to find any help on. I
I have a very big problem and can't seem to find anybody else on
I've tried to search around for the answer to this question, but can't seem
I've searched for this term, and can only find a few references, but i've
I can't seem to figure this one out. I have the following XML file:
I can't seem to find how to do this anywere, I am trying to
been having this problem for a few days now and can't seem to find
My problem is that I can only seem to click the button once, if
Can't locate stored files, but they seem to be downloaded only for the first
I can only assume this is a bug. The first assert passes while the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.