none
Visual basic express getting results between two characters. My results are truncate, why? RRS feed

  • Question

  • i need help with a VB 2017 regex issue.  I have the following text:

    RAY Ticket: 235556986 | Users complain boom application is not accessible on host ulpv0725.madc.bbb.com. We cannot log into this host to investigate - login hangs. This host has been removed from load balancer and other hosts now take more hits. | 

    I want to capture the text between the the two "|".  Using the following code:

            Dim mc As MatchCollection = Regex.Matches(DI.Text, "\d\d:\d\d") ' This was an initalization and unrelated searvh

    mc = Regex.Matches(DI.Text, "RAY Ticket:.\d+..[^\|]*")
            Try
                desc.Text = mc(0).ToString()

            Catch
                desc.Text = "Error"
            End Try

    my result is this:

    | Users complain boom application is not accessible on host ulpv0725.madc.bbb.com.

    What is stopping me from getting the complete results?
    Friday, September 1, 2017 8:13 PM

All replies

  • Hi

    Here is one way.

     Dim s As String = "RAY Ticket: 235556986 | Users complain boom application is not accessible on host ulpv0725.madc.bbb.com. We cannot log into this host to investigate - login hangs. This host has been removed from load balancer and other hosts now take more hits. | "
     Dim a() As String = Split(s, "|")
     MessageBox.Show(a(1))
    


    Regards Les, Livingston, Scotland

    Friday, September 1, 2017 8:17 PM
  • Regx seems overkill here

    Dim input As String = "RAY Ticket: 235556986 | Users complain boom application is not accessible on host ulpv0725.madc.bbb.com. We cannot log into this host to investigate - login hangs. This host has been removed from load balancer and other hosts now take more hits. | "
    Dim rx As New Regex("[^|""]+|""([^""]*)""'([^']*)'", RegexOptions.Compiled)
    
    For Each m As Match In rx.Matches(input)
        Console.WriteLine(m.Value)
    Next

    Results

    RAY Ticket: 235556986 
     Users complain boom application is not accessible on host ulpv0725.madc.bbb.com. We cannot log into this host to investigate - login hangs. This host has been removed from load balancer and other hosts now take more hits. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, September 1, 2017 10:25 PM
    Moderator
  • Thanks your answer is excellent for this situation.  excuse me for not providing the whole text which has plenty "|" that's why I chose regex to extract it.  But your solution is great for future reference and when I can extract that group.  Thanks for the alternative.
    Saturday, September 2, 2017 4:15 AM
  • Hi Jmosley,

    It seems that you have solved your issue now, please remember to close your thread by marking the helpful post as answer, it is beneficial to other community members who face the same issue.

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 8, 2017 1:31 AM
    Moderator