ASP Regular Expression Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sin010101
    New Member
    • May 2010
    • 1

    #1

    ASP Regular Expression Help

    I am trying to pull out an ID number from a string, but cannot figure it out. I have this regex:

    Dim string
    string = "newline <html><body>new line NAME: John Doe<br />SUBSCRIBER ID: 0010101 <span>more text</span>"

    Set SubsriberRegEx = New RegExp
    With SubsriberRegEx
    .Pattern = "SUBSCRIBER\s+I D:\s+(\d+)"
    .IgnoreCase = True
    .Global = True
    End With

    What i want to do is just print out $1, the closest thing i have found is:
    Response.Write( SubsriberRegEx. Replace(string, "Subscriber ID: $1"))

    Which Prints out:
    Subscriber ID: 0010101 more text

    Notice the "more text". The problem is that the variable "string" is actually a huge file with a lot of weird characters inside of it.

    I know i could change this example regex to:
    .Pattern = "SUBSCRIBER\s+I D:\s+(\d+).*"

    and that would work in this example, but the file I am using has a lot of characters that ".*" do not match, such as special characters, tabs, newlines.

    Is there a way to only access $1 without using the Replace method?
    maybe something like:
    Set SubscriberID = SubsriberRegEx. Execute(string) .$1

    Any help would be much appreciated.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    is there any way to narrow down how many characters the id will be? is there always a space after it? Is there ever a space in the midst of the ID?

    Jared

    Comment

    Working...