Results 1 to 4 of 4

Thread: [2008] Regular Expressions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    135

    [2008] Regular Expressions

    Hi,

    I'm really, really stuggling with this...

    How can I find somethign betwee two strings? Here is an example

    start data data data
    more data on new line
    extra data end

    I want it to get everything between "start" and "end". I have tried basic things like: "start(.*)end" with multiple line and ignore case settings but I cant get it to work.

    Any help would be greatly appreciated

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Regular Expressions

    try this

    vb Code:
    1. Dim testStr As String = "start data data data" & Environment.NewLine & _
    2.                                    "more data on new line" & Environment.NewLine & _
    3.                                    "extra data end"
    4. Dim rx As New Regex("(?<=start)(\n| |.)*(?=end)", RegexOptions.IgnoreCase)
    5. MsgBox(rx.Match(testStr).Value)

  3. #3
    New Member
    Join Date
    Jul 2008
    Posts
    12

    Re: [2008] Regular Expressions

    I am going nuts with regex as well :P anyone care to help me parse "341" out of the string below please:

    Code:
    Score   341   0

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Regular Expressions

    Quote Originally Posted by The_Patzer
    I am going nuts with regex as well :P anyone care to help me parse "341" out of the string below please:

    Code:
    Score   341   0
    you should start a new thread really.

    try this

    vb.net Code:
    1. Dim testStr As String = "Score   341   0"
    2. Dim rx As New Regex("(?<=Score( )*)\d*(?=( )*0)", RegexOptions.IgnoreCase)
    3. MsgBox(rx.Match(testStr).Value)

    it'd be easier without regex:

    vb.net Code:
    1. Dim testStr As String = "Score   341   0"
    2. Dim strArray() As String = testStr.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)
    3. msgbox (strArray(1))
    Last edited by .paul.; Jul 20th, 2008 at 01:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width