tags:

views:

92

answers:

3

i have a text file which contains lots of email addresses from my old address book. I need to get these out of it. every email addy is preceeded with

ip:

and ends with

\

for example

blablablaip:[email protected]\

the addresses are up to 25 characters in length(not sure if that makes a difference for the required regex im a noob) and sometimes there is a line break in the middle of an address, i.e an email address is split between the end of a line and the start of a new line.

Any of you regex wizards offer me any help please?

thanks in advance

+1  A: 

You can try this regex :

/ip:(.{0,25}?)\/

It works like this :

/         <- The delimiter of your regex
    ip:       <- Matches the "ip:" part
    (             <- Open a capture group
        .         <- Matches any character 
        {0,25}    <- Last part repeated between 0 and 25 times
        ?         <- Ungreedy modifier, to capture less elements possible (in the 0, 25 limit)
    )         <- End of the capture group
    \         <- The "\" part
/         <- End of the regex

In C# you don't need delimiters in your regex so you can use this :

@"ip:(.{0,25}?)\\" //Don't forget to escape the \ 

Resources :

Colin Hebert
thanks very much appreciated i understand what you say :)
brux
A: 

regex you're looking for is

ip:(.*?)\\
Max
A: 

You might want to strip the line-breaks, just for simplicity.

After that:

String regex = @"ip:(?'email'(.*)@(.*\.*))\\";

No length restrictions or character restrictions, but it will match the [email protected] part of a email and place it in the email group.

peachykeen