# Powershell and Regex

**URL:** <https://forums.powershell.org/t/powershell-and-regex/3023>\
**Category:** PowerShell Help\
**Created:** [August 26, 2014, 1:18pm UTC](https://forums.powershell.org/t/powershell-and-regex/3023 "2014-08-26T13:18:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![john-beck](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@john-beck](https://forums.powershell.org/u/john-beck)\
**Post date:** [August 26, 2014, 1:18pm UTC](https://forums.powershell.org/t/powershell-and-regex/3023/1 "2014-08-26T13:18:56Z")

</div>

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

[zzzpbxwer123@domain.com](mailto:zzzpbxwer123@domain.com)  
[zzzpbxyx8t@domain.com](mailto:zzzpbxyx8t@domain.com)  
[123@domain.com](mailto:123@domain.com)  
[xyz@domain.com](mailto:xyz@domain.com)  
(555)-123-4567  
[zz@domain1.net](mailto: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

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [August 26, 2014, 11:53pm UTC](https://forums.powershell.org/t/powershell-and-regex/3023/2 "2014-08-26T23:53:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john-beck](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@john-beck](https://forums.powershell.org/u/john-beck)\
**Post date:** [August 27, 2014, 12:02am UTC](https://forums.powershell.org/t/powershell-and-regex/3023/3 "2014-08-27T00:02:49Z")

</div>

Don,

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

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [August 27, 2014, 12:14am UTC](https://forums.powershell.org/t/powershell-and-regex/3023/4 "2014-08-27T00:14:06Z")

</div>

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](http://regextester.com) a lot to play with regexes and get them tweaked. There’s also [regexlib.com](http://regexlib.com) which has a lot of pre-made ones.

---

<div class="post-metadata">

**Author:** ![john-beck](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@john-beck](https://forums.powershell.org/u/john-beck)\
**Post date:** [August 27, 2014, 12:22am UTC](https://forums.powershell.org/t/powershell-and-regex/3023/5 "2014-08-27T00:22:19Z")

</div>

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

gc input.txt | Select-String “^zzz@domain.com”

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:47pm UTC](https://forums.powershell.org/t/powershell-and-regex/3023/6 "2024-05-16T20:47:37Z")

</div>


