Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

pretty basic pattern..vbscript

Last post 05-14-2008, 7:39 PM by Aussie Susan. 2 replies.
Sort Posts: Previous Next
  •  05-14-2008, 12:49 PM 42257

    pretty basic pattern..vbscript

    vbscript Regex question here... 

    I have a string that will/should contain either a 5 digit number "12345" or a record number that will be something like "ABC_E00012345", separated by whitespace character
    I would like to match each individual instance of the 2 possibilities above.

    Example String:  12345 ABC_E12345 54321 98765 ABC_E98765 00 123 A

    What I would like to match:
    12345
    ABC_E12345
    54321
    98765
    ABC_E98765

    What I would like to discard, or just not return:
    00
    123
    A

    The pattern I came up with is returning such things as 00 123 A, can anyone help?

    objRegEx.Pattern = "[^\d{5}$]|^ABC_E000[\d{5}$]"

    Also, if possible can someone give me the in a nutshell of when and where to use ^ or $ inside or outside bracket/paren

     

    Thanks everyone! 

     

     

  •  05-14-2008, 3:38 PM 42264 in reply to 42257

    Re: pretty basic pattern..vbscript

    yfki:

    vbscript Regex question here... 

    I have a string that will/should contain either a 5 digit number "12345" or a record number that will be something like "ABC_E00012345", separated by whitespace character
    I would like to match each individual instance of the 2 possibilities above.

    Example String:  12345 ABC_E12345 54321 98765 ABC_E98765 00 123 A

    What I would like to match:
    12345
    ABC_E12345
    54321
    98765
    ABC_E98765

    What I would like to discard, or just not return:
    00
    123
    A


     You'll need to give more detail of what makes up a valid record number.

    yfki:

    The pattern I came up with is returning such things as 00 123 A, can anyone help?

    objRegEx.Pattern = "[^\d{5}$]|^ABC_E000[\d{5}$]"

    Also, if possible can someone give me the in a nutshell of when and where to use ^ or $ inside or outside bracket/paren

     

    Thanks everyone! 

     

     

    You are misusing the Character Class. http://regexadvice.com/blogs/mash/archive/2008/01/31/A-touch-of-Character-Class.aspx


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  05-14-2008, 7:39 PM 42268 in reply to 42257

    Re: pretty basic pattern..vbscript

    How about:

    \b(\d{5}|[a-z]\S+)\b

    with the 'ignore case' option set.

    This assumes that the 'record number' is an alphabetic character followed by any number of non-space characters. If there is a set limit, or a valid number range, then change the "\S+" to the "\S{min,max}" form or modify it to whatever meets your requirement.

    The '\b' placeholders are the trick here.

    Also, I'm surprised that your pattern picks up anything from the test text you have supplied - even if you do change it to use character classes correctly. What I think you are trying to achieve with what you have written is going to force the number or 'record number' to be the only thing in the text: the '^' says to match only the very start of the text and the '$' says to match only the very end of the text (assuming the 'multiline' option is off). This means that it will not match anything in your example.

    Susan 

View as RSS news feed in XML