c# regex string,anyone know how?
i have a text file which contains lots of email addresses from my old addre开发者_如何学Css book. I need to get these out of it. every email addy is preceeded with
ip:
and ends with
\
for example
blablablaip:me@you.com\
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
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 :
- regular-expression.info - Repetition
regex you're looking for is
ip:(.*?)\\
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 xxx@xx.x part of a email and place it in the email group.
精彩评论