Collection based on PC name using Regex/pattern matching?
Craig Mohr
This question is because I admittedly suck at RegEx. Can anyone help me make a collection of PC's that are named anything with a number on the end or -NEW or -OLD? I am trying to clean up a bunch of junk our help desk made that does not follow guidelines.
Bonus if it does not match ##demo# (10demo1) but not required I can work around that.
1
Comments
Try this:
^([A-Za-z]\w+)(\d+|-[Nn][Ee][Ww]|-[Oo][Ll][Dd])
[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.
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.
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!
Thanks Colby, I didn't realize that regex was case-insensitive in Inventory.
Glad it worked out for you, Craig.