Results 1 to 4 of 4

Thread: Regex help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Posts
    262

    Question Regex help

    Hi Guys,

    I am trying to use a regular expression to find a certain string within a textbox.

    Is it possible to include the equals sign (=) within the regex so it looks for this? When i type the equals sign within the regex it doesn't fnid it any more.

    Works when searching this string - "and JobID 816138</Detail>":
    Code:
    Dim MatchJobId As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(MyResults, "(?<=and JobID ).+?(?=</Detail>)", System.Text.RegularExpressions.RegexOptions.Singleline)
    Don't Work when searching "?JobID=816138</Detail>":
    Code:
    Dim MatchJobId As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(MyResults, "(?<=?JobID=).+?(?=</Detail>)", System.Text.RegularExpressions.RegexOptions.Singleline)
    Do i have to use different characters for the = and ? sign when they are being included within the regex search?

    Thanks,
    Chloe ~X~

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Regex help

    I think you'll need to use the bar (\) for those chars...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

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

    Re: Regex help

    did that help?
    the \ character is an escape character

  4. #4
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Regex help

    have a look there : http://msdn.microsoft.com/en-us/library/1400241x%28VS.85%29.aspx It was very helpful to me when I had to work with regular expressions.

    The "=" character is used for Positive lookahead so escaping it with the backslash character as previously suggested should work for that.
    Your problem might also come from the "?" character which is a Metacharacter
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

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