could someone show me how to use RegExp

Discussion in 'Scripting' started by tin, Sep 30, 2004.

  1. tin

    tin Guest

    here is my example:
    some gibberish here
    \\computername description
    how do i go about retrieving just the computer name. there's no fixed spaces
    and could be tab in between.

    tin, Sep 30, 2004
    1. Advertisements

  2. tin

    Jeff Cochran Guest

    Some help:

    The key would be the pattern, something like:

    objRegExp.Pattern = "\\\S*"

    Should be any string beginning with "\\" and having non-whitespace
    characters. Not sure if the double backslash has any special meaning,
    since the "\" character indicates a special character, give it a try.

    Jeff Cochran, Oct 1, 2004
    1. Advertisements

  3. tin

    tin Guest

    Thanks Jeff, but unfortunately that didn't work very well.
    Here's the code i got from a buddy of mine in case someone is curious about
    ' find pattern p in string s and return first match
    Function FindPattern(s, p)
    Dim regEx, Match, Matches ' Create variable.
    Set regEx = New RegExp ' Create regular expression.
    regEx.Pattern = p ' Set pattern.
    regEx.IgnoreCase = True ' Set case insensitivity.
    Set Matches = regEx.Execute(s) ' Execute search.
    For each match in Matches
    FindPattern = match.value
    End Function

    sTest = "\\computername p4 workstation"
    MsgBox(FindPattern(sTest, "\w+"))

    tin, Oct 1, 2004
  4. tin

    Jeff Cochran Guest

    Not sure how a \w+ would work. That matches A-Z, a-z, numbers and the
    underscore, to the end of the string beginning with the first match.
    Which means in your file sample:

    some gibberish here
    \\computername description

    You would match on "Some" and then nothing else. If your text file
    has a single line, or you test on a line by line basis, and the
    computer name always follows non-alpha/non-numerics as the first word,
    your solution will work. It also works with the test data provided in
    your script example. If that test data is representative of your true
    data, then you have your answer.

    Jeff Cochran, Oct 4, 2004
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.