Author Posts

March 30, 2017 at 2:29 pm

Hi,

I'm fighting to make a regex to find any text after a space and before an @ and any text before that until it reaches a whitespace again...

$myString = @"
dys dkan jdna user@domain.no hhaksda d asda user@domain.com
dsad ada sdd asd manolo.andrade@dominio.com.br fdfsd 
dsajklg test.user@domain.net
"@

Using this:

(Select-String -InputObject $myString -Pattern '\w+@\w+\.\w+.\w+' -AllMatches).Matches | ft * -AutoSize

I only get the andrade@dominio.com.br without the manolo...
I want to find any text that has a @ in the middle... (Ex.: te@aol.com, test.teste_teste@test.com.br, etc)

March 30, 2017 at 2:52 pm

You could use a pattern like that

'\S+@\w+\.\w*\.*\w+'

and it fits with the examples you posted but a little more sofisticated would be this I think

'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b'

😉

March 30, 2017 at 4:58 pm

Olaf Soyk,

You're the man! Thanks a lot!