Regex to find any text separated by an @

This topic contains 3 replies, has 2 voices, and was last updated by  Olaf Soyk 6 months, 3 weeks ago.

  • Author
    Posts
  • #67599

    Vandrey Trindade
    Participant

    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)

  • #67602

    Olaf Soyk
    Participant

    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'

    😉

  • #67639

    Olaf Soyk
    Participant

    De nada. 😉

You must be logged in to reply to this topic.