Считаете, что Ubuntu недостаточно дружелюбна к новичкам? Помогите создать новое Руководство для новичков!
0 Пользователей и 1 Гость просматривают эту тему.
<body>(.*)</body>
"<body>ololololoqwe</body>"
PCRE_ANCHORED Match only at the first positionPCRE_BSR_ANYCRLF R matches only CR, LF, or CRLFPCRE_BSR_UNICODE R matches all Unicode line endingsPCRE_NEWLINE_ANY Recognize any Unicode newline sequencePCRE_NEWLINE_ANYCRLF Recognize CR, LF, & CRLF as newline sequencesPCRE_NEWLINE_CR Recognize CR as the only newline sequencePCRE_NEWLINE_CRLF Recognize CRLF as the only newline sequencePCRE_NEWLINE_LF Recognize LF as the only newline sequencePCRE_NOTBOL Subject string is not the beginning of a linePCRE_NOTEOL Subject string is not the end of a linePCRE_NOTEMPTY An empty string is not a valid matchPCRE_NOTEMPTY_ATSTART An empty string at the start of the subjectis not a valid matchPCRE_NO_START_OPTIMIZE Do not do "start-match" optimizationsPCRE_NO_UTF8_CHECK Do not check the subject for UTF-8validity (only relevant if PCRE_UTF8was set at compile time)PCRE_PARTIAL ) Return PCRE_ERROR_PARTIAL for a partialPCRE_PARTIAL_SOFT ) match if no full matches are foundPCRE_PARTIAL_HARD Return PCRE_ERROR_PARTIAL for a partial matcheven if there is a full match as well
Нашёл, что . - любой символ, кроме этого самого злополучного \n. Как можно извернуться, чтобы подходил вообще-любой-символ между тегами?
<body><q>1</q><a>11</a><m>10</m></body><body><q>2</q><a>22</a><m>10</m></body><body><q>3</q><a>33</a><m>10</m></body>
#include <stdio.h>#include <string.h>#include <pcre.h>int main(int argc, char** argv){ char* regex = "<body>(.*)</body>"; char* str = "<body>" "<q>1</q>" "<a>11</a>" "<m>10</m>" "</body>" "<body>" "<q>2</q>" "<a>22</a>" "<m>10</m>" "</body>" "<body>" "<q>3</q>" "<a>33</a>" "<m>10</m>" "</body>"; const char *error; int erroffset; pcre *re; int rc; int i; int ovector[100]; re = pcre_compile (regex, /* the pattern */ PCRE_DOTALL | PCRE_UNGREEDY, &error, /* for error message */ &erroffset, /* for error offset */ 0); /* use default character tables */ if (!re) { printf("pcre_compile failed (offset: %d), %s\n", erroffset, error); return -1; } unsigned int offset = 0; unsigned int len = strlen(str); while (offset < len && (rc = pcre_exec(re, 0, str, len, offset, 0, ovector, sizeof(ovector))) >= 0) { for(int i = 0; i < rc; ++i) { printf("%2d: %.*s\n", i, ovector[2*i+1] - ovector[2*i], str + ovector[2*i]); } offset = ovector[1]; } return 1;}
Страница сгенерирована за 0.018 секунд. Запросов: 21.