views:

209

answers:

3

There is no default RegEx library on the iPhone. Is it ok if I use UIWebView's stringByEvaluatingJavaScriptFromString to evaluate a JavaScript string that actually uses the RegExp object to evaluate an expression? Is this supported on the iPhone?

+2  A: 

Of course, you can always just try it and find out, but there's probably another way to get what you need. The NSPredicate class, for example, allows string matching on regular expressions. If you need to do searching, I'm not sure about that, but take a look at this article for matching anyway.

Ed Marty
+1  A: 

There is the BSD "C" regex library on the iPhone, I have used it in a couple of apps. man:regex

zaph
+1  A: 

Yes, it's possible, here's a sample code. The idea behind doing it this way might be to support Javascript-compliant Regular Expressions, leading to reuse and portability of existent JS Regexp code you might have:

UIWebView *wb = [[UIWebView alloc] init];
NSLog(@"%@", [wb stringByEvaluatingJavaScriptFromString:
                          @"re = new RegExp('su{1,3}p+er'); re.test('suuuper')"]);
luvieere