Collection based on PC name using Regex/pattern matching?



  • Luke Nichols

    Try this:

    [A-Za-z] matches any letter
    \w matches any alphanumeric character
    \d matches any number
    + is a quantifier saying match 1 or more of the preceding token
    | means OR
    The parentheses are just here to encapsulate a token so the OR logic is more obvious

    - literally matches a hyphen
    [Nn][Ee][Ww] matches any capitalization of "new"
    [Oo][Ll][Dd] matches any capitalization of "old"

    This won't match ##demo# since it won't match anything that begins with a number.

    Comment actions Permalink
  • Colby Bouma

    Regular expressions are case insensitive in Inventory. Here's my submission:


    I tested my pattern in PowerShell because Inventory and PowerShell both use .NET regex.

    $TestStrings = @(
    $Pattern = '^[a-z]\w+(\d+|-(new|old))'

    foreach ( $TestString in $TestStrings ) {

    'Test String' = $TestString
    'Matches Pattern' = $TestString -match $Pattern


    Comment actions Permalink
  • Craig Mohr

    Awesome thanks guys. I used Colby's because it's a bit easier to read. Works great. Luke's works as well if you add ^ to the beginning otherwise it picks up those demo names. Thanks both of you for the assist!

    Comment actions Permalink
  • Luke Nichols

    Thanks Colby, I didn't realize that regex was case-insensitive in Inventory.

    Glad it worked out for you, Craig.

    Comment actions Permalink

Please sign in to leave a comment.