Pattern Matching

Discussion in 'ASP .Net' started by Eric, Aug 7, 2006.

  1. Eric

    Eric Guest

    I use RegEx to search pattern. Script works fine in the situation when
    there is a colon after each word and it fetch the rest of the word from
    that line. Now the pattern is in square bracket and i need help how to
    change that line (sPattern =

    "From\:\s*([\s\S]+?)[\r\n]+") so that it search pattern in a square
    bracket and fetch the next line of that pattern.


    Dim fso, fil, ts, sContents
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set fil = fso.getfile(server.mappath("myemails.txt"))
    Set ts = fil.openastextstream(1)
    sContents = ts.readall
    sPattern = "From\:\s*([\s\S]+?)[\r\n]+"
    Dim rx
    Set rx = New RegExp
    rx.Global = True
    rx.IgnoreCase = True
    rx.MultiLine = True
    rx.Pattern = sPattern
    Set mc = rx.Execute(sContents)
    Set rm = mc.Item(0)
    sFrom = rm.SubMatches(0)
    response.write(sFrom)
    ts.close
    Set rx = nothing
    Set ts = nothing
    Set fil = nothing
    Set fso = nothing


    -----SAMPLE DATA--------
    [Date]
    Sat Aug 05 14:06:12 EDT 2006

    [Novell ID]
    NSMITH4

    [Subject]
    PPV / VOD Research - Dispute - 1st Time - 711579

    [Customer's Name]
    EDWARD CAMPBELL
     
    Eric, Aug 7, 2006
    #1
    1. Advertising

  2. \[([^][]+)\]

    Matches square brackets and anything between them. Puts the characters
    between the square brackets into Group 1.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Chicken Salad Surgery

    Expect the unaccepted.

    "Eric" <> wrote in message
    news:...
    >I use RegEx to search pattern. Script works fine in the situation when
    > there is a colon after each word and it fetch the rest of the word from
    > that line. Now the pattern is in square bracket and i need help how to
    > change that line (sPattern =
    >
    > "From\:\s*([\s\S]+?)[\r\n]+") so that it search pattern in a square
    > bracket and fetch the next line of that pattern.
    >
    >
    > Dim fso, fil, ts, sContents
    > Set fso = Server.CreateObject("Scripting.FileSystemObject")
    > Set fil = fso.getfile(server.mappath("myemails.txt"))
    > Set ts = fil.openastextstream(1)
    > sContents = ts.readall
    > sPattern = "From\:\s*([\s\S]+?)[\r\n]+"
    > Dim rx
    > Set rx = New RegExp
    > rx.Global = True
    > rx.IgnoreCase = True
    > rx.MultiLine = True
    > rx.Pattern = sPattern
    > Set mc = rx.Execute(sContents)
    > Set rm = mc.Item(0)
    > sFrom = rm.SubMatches(0)
    > response.write(sFrom)
    > ts.close
    > Set rx = nothing
    > Set ts = nothing
    > Set fil = nothing
    > Set fso = nothing
    >
    >
    > -----SAMPLE DATA--------
    > [Date]
    > Sat Aug 05 14:06:12 EDT 2006
    >
    > [Novell ID]
    > NSMITH4
    >
    > [Subject]
    > PPV / VOD Research - Dispute - 1st Time - 711579
    >
    > [Customer's Name]
    > EDWARD CAMPBELL
    >
     
    Kevin Spencer, Aug 8, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DelphiDude
    Replies:
    3
    Views:
    1,190
  2. danpres2k
    Replies:
    3
    Views:
    7,519
    danpres2k
    Aug 25, 2003
  3. CV
    Replies:
    2
    Views:
    608
    Charles DeRykus
    Aug 31, 2004
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    262
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    266
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page