View Single Post
Old 12-19-2006   #2 (permalink)
Rob Campbell


 
 

RE: Regular expressions

How about:

$string -match "(\w+)@.+"
$string = "$($matches[1]),<email removed>"

"Marco Shaw" wrote:

> I'd like to take these 2 general strings and replace them:
> email@email.com
> "email@email.com" <domain@domain.com>
>
> [C:\psh]
> 148> $string=email@email.com
> [C:\psh]
> 151> $string -replace ('@\w.+','<email removed>')
> email<email removed>
> [C:\psh]
> 152> $string="`"email@email.com`" <domain@domain.com>"
> [C:\psh]
> 153> $string
> "email@email.com" <domain@domain.com>
> [C:\psh]
> 154> $string -replace ('@\w.+','<email removed>')
> "email<email removed> <--The remainder gets dropped...
> [C:\psh]
>
> So apart from trying to match the 2 strings above...
>
> Also, can one do something like:
> $string -replace ('a','1' && 'b','2')
>
> The intent above would be that a is replaced by 1 *and* b is replaced by 2.
> Realizing that one could probably do some nesting and accomplish the same
> thing...
>
> Marco
>
>
>

My System SpecsSystem Spec