I am making an iphone application. I have a scenario where i have a huge string, which has lot of data, and i would like to extract only email addresses from the string.
For example if the string is like
asdjasjkdh asdhajksdh jkashd sample@email.com asdha jksdh asjdhjak sdkajs test@gmail.com
i should extract “sample@email.com” and “test@gmail.com”
and i also want to extract only date, from the string
For example if the string is like
asdjasjkdh 01/01/2012 asdhajksdh jkas 12/11/2012 hd sample@email.com asdha jksdh asjdhjak sdkajs test@gmail.com
i should extract “01/01/2012” and “12/11/2012”
A small code snipet, will be very helpful.
Thanks in advance
This will do what you want:
Using your sample string above:
The output is:
To use the code, just set
searchStringto the string you want to search. Instead of the NSLog() methods, you’ll probably want to do something with the extracted stringsmatchText. Feel free to use a different regex string to extract emails, just replace the value ofregexStringin the code.