#1
  1. No Profile Picture
    Dim Brendan as Noob
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    478
    Rep Power
    506

    [VB 2008] Regex Using "." to INCLUDE line breaks


    I want to start by searching for "strong" and end by searching for "npc" and match everything in between with an unknown number of line breaks. How do I accomplish this? using ".*\n*" doesn't work because it searches for any character and then any number of line breaks. I need them to be combined.

    Thank you in advance.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    Look at the RegexOptions enum. It has an option specifically for that behavior.

    Comments on this post

    • Brendan.C agrees : Thank you for the refrence, it's a start but I still can't acomplish what I need to.
  4. #3
  5. No Profile Picture
    Dim Brendan as Noob
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    478
    Rep Power
    506
    My apologies, It's been a while since I've done this and can't seem to make it work.

    Code:
            getpost(server + "/pages/raid_result.php?id=145748", "GET", "")
    pattern = "strong.*npc.*\r$"
    MsgBox(Regex.Match(responseFromServer, pattern, RegexOptions.Multiline).ToString)
    Still doesn't work. Can you elaborate?
  6. #4
  7. No Profile Picture
    Dim Brendan as Noob
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    478
    Rep Power
    506
    I have figured it out. It was deceiving because instead of using "Multiline" I actually needed to use "Singleline" which did exactly as I was looking for, it made "." match every character including a new line. Thank you again.
  8. #5
  9. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    Yes, that's it. Multiline means that start- and end-of-string anchors (^ and $) match the beginning and end of every line - as in your input has multiple lines but you want ^ and $ to be even more useful.
    Singleline is like saying to treat the entire thing as if it were just the one line - newline characters are just more bytes and dot-all should match them too.

    At least that's how I think of it.
  10. #6
  11. No Profile Picture
    Dim Brendan as Noob
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    478
    Rep Power
    506
    I thought enough time had passed to add to your reputation again but it hasn't. In any case thank you again and your explanation definitely helped clear that up for me. I've been on this board for almost a decade and the wonderful people here never cease to amaze me.

IMN logo majestic logo threadwatch logo seochat tools logo