Hession
Hession

Reputation: 31

How to prevent pcre(C library) to continue matching when it failed in one string?

If I have a string and a pattern:

char src[]="\"http://www.aaa.cn\"</tab><tab>\"www.bbb.com\""; 
char pattern[] = "\"http:\/\/.*\.com\"";  

Then it returns "http://www.aaa.cn\"</tab><tab>\"www.bbb.com" to me (it failed but continue matching next characters).

I just want some like "http://www.aaa.com", "http://www.bbb.com", not like that combined string.

Can someone help me out? Should I change my pattern or add some arguments to pcre_compile() and pcre_exec() functions?

Upvotes: 1

Views: 123

Answers (1)

pilcrow
pilcrow

Reputation: 58589

Try this.

char pattern[] = "\"http://[^\"]*\"";

Better yet, don't parse HTML (or fragments thereof or XML) with regexen.

Upvotes: 2

Related Questions