ios - Regex for date and replace its occurrence in string using stringByReplacingMatchesInString -


i need regex date this, "dd/mm/yyyy hh:mm:ss pm" , want separate string components using regex match in nsstring.

for example if string is,

30/06/15 11:46:37 pm: person1: testing 30/06/15 11:46:40 pm: person1: hello... 30/06/15 11:46:52 pm: person2: hi  30/06/15 11:47:06 pm: person1: how doing 

and output components in array should be,

person1: testing person1: hello... person2: hi  person1: how doing 

you can suggest better idea parse string contains chat text above mentioned.

try this, nsstring *string = @"30/06/15 11:46:37 pm: person1: testing 30/06/15 11:46:40 pm: person1: hello... 30/06/15 11:46:52 pm: person2: hi 30/06/15 11:47:06 pm: person1: how doing"; nserror *error = nil; nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:@"([0-9]{1,2})+\/+([0-9]{1,2})+\/+([0-9]{1,2})+ +([0-9]{1,2})+:+([0-9]{1,2})+:+([0-9]{1,2}) +(am|pm): " options:nsregularexpressioncaseinsensitive error:&error]; nsstring *modifiedstring = [regex stringbyreplacingmatchesinstring:string options:0 range:nsmakerange(0, [string length]) withtemplate:@""]; nslog(@"%@", modifiedstring); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -