Author Posts

August 26, 2014 at 6:48 pm

I have a text file called input.txt. The file's content is similar to below:

zzzpbxwer123@domain.com
zzzpbxyx8t@domain.com
123@domain.com
xyz@domain.com
(555)-123-4567
zz@domain1.net

I need to just get the line in the format zzzpbx*@domain.com. Meaning, all the strings I am looking to get start with zzzpbx and end with @domain.com. In between it could be any number of letters or digits. Any ideas?

Thanks

August 27, 2014 at 5:23 am

Use Select-String. You probably don't even need a regex, a simple wildcard zzzpbx*@domain.com would probably work.

August 27, 2014 at 5:32 am

Don,

Thanks. However, the application where I need to use this does not allow for wild cards.

August 27, 2014 at 5:44 am

Oh, okay. Well, a regex would just be something like zzzpbk[\w]+@domain\.com

\w meaning letters and numbers, but not spaces or punctuation. Adjust as needed. There's about about_regular_expressions help file in PowerShell with the basic syntax, and I use regextester.com a lot to play with regexes and get them tweaked. There's also regexlib.com which has a lot of pre-made ones.

August 27, 2014 at 5:52 am

that would work. I was using the below but it obviously was missing few things

gc input.txt | Select-String "^zzz\@domain.com"