Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to write a appropriate pattern in pcre with C
    primarykey
    data
    text
    <p>Now I have a string which has many substring like "href="http://www.AAA.com"" and other characters, Here my question,In my C code I write :</p> <p>char pattern[] = "/^href.*>$/g";</p> <p>and I want to pick up all the urls in the long string. But it doesn's work.Can SomeBody help me? Your help will be appreciated. Here is the Code:</p> <pre><code>#define PCRE_STATIC // #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;pcre.h&gt; #define OVECCOUNT 30 /* should be a multiple of 3 */ #define EBUFLEN 128 #define BUFLEN 1024 int main() { pcre *re; const char *error; int erroffset; int ovector[OVECCOUNT]; int rc, i; char src[] = "&lt;a href=\"http://union.elong.com/r/hotel/2000000000855850825\" target=\"_blank\"&gt;ss&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;a href=\"http://123.sogou.com/sub/fanyi.html\" targedd&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=\"http://123.sogou.com/sub/fantizi.html\" target=\"_blank\"&gt;繁 体 字&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=\"http://123.sogou.com/sub/kuaidi.htm&gt;快递查询&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;a href=\"http://q.stock.sohu.com/index.shtm&gt;股票行情&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=\"http://www.chinamobile.com/service/billservice/&gt;话费查询&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href=\"http://auto.sohu.com/s2004/weizhangchaxun.shtml&gt;交通违章&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;"; char pattern[] = "/^href.*&gt;$/g"; re = pcre_compile(pattern, 0, &amp;error, &amp;erroffset, NULL); if (re == NULL) { printf("PCRE compilation failed at offset %d: %s\n", erroffset, error); return 1; } rc = pcre_exec(re, NULL, src, strlen(src), 0, PCRE_MULTILINE, ovector, OVECCOUNT); if (rc &lt; 0) { if (rc == PCRE_ERROR_NOMATCH) printf("Sorry, no match ...\n"); else printf("Matching error %d\n", rc); pcre_free(re); return 1; } printf("\nOK, %d has matched ...\n\n",rc); for (i = 0; i &lt; rc; i++) { char *substring_start = src + ovector[2*i]; int substring_length = ovector[2*i+1] - ovector[2*i]; printf("$%2d: %.*s\n", i, substring_length, substring_start); } pcre_free(re); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload