Does anyone have a good regex for this? For instance:
This is *an* example
should become
This is <b>an</b> example
I need to run this in Objective-C, but I can probably work as it should. This is a regular expression that gives me trouble (so rusty ...). Here is what I still have:
s/\*([0-9a-zA-Z ])\*/<b>$1<\/b>/g
But it does not seem to work. Any ideas? Thank:)
EDIT: Thanks for the answer :) If anyone is interested in how it looks in Objective-C using RegexKitLite:
NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:@"\\*([0-9a-zA-Z ]+?)\\*" withString:@"<b>$1<\\/b>"];
EDIT AGAIN: Actually, to cover more characters for bold, I changed it to the following:
NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:@"\\*([^\\*]+?)\\*" withString:@"<b>$1<\\/b>"];
source
share