PCRE question regebuddy work but in code no?

10 views
Skip to first unread message

stefano cerbioni

unread,
Apr 21, 2022, 12:37:51 PM4/21/22
to pcre...@googlegroups.com
hi guys sorry for disturb i have a strign like this
[{"symbol":"BTCUSDT", ... etc
i want match BTCUSDT , i create this: symbol":"(.*?)" but in
regexpbuddy (with PCRE) work perfect but if i give at my script not
match
anyone have idea?? thanks

my code
// -----------------------------------------------------------------------------------
// ---------------------------- REGEXP IN PERL STYLE
---------------------------------
// -----------------------------------------------------------------------------------

if ( strcmp(StyleRgXp, "p") == 0) {
pcre *re;
const char *error;
int erroffset;
int ovector[OVECCOUNT];
int rc, i;
char *substring_start ;

//char src[] = "111 <title>Hello World</title> 222";
//char pattern[] = "<title>(.*)</title>";

// printf("String : %s/n", TesTsSubj);
// printf("Pattern: %s/n", PatterN);


re = pcre_compile(PatterN, 0, &error, &erroffset, NULL);
if (re == NULL) {
printf("PCRE compilation failed at offset %d: %s/n",
erroffset, error);
//return 1;
}


// MATCH FIRST OCCURRENCE
******************************************************************
rc = pcre_exec(re, NULL, TesTsSubj, strlen(TesTsSubj), 0, 0,
ovector, OVECCOUNT);
if (rc < 0) {
if (rc == PCRE_ERROR_NOMATCH) substring_start
=("Sorry, no match .../n"); //printf("Sorry, no match .../n");
else substring_start = ("Matching error %d/n");//
printf("Matching error %d/n", rc);
//free(re);
//return 1;
}

//printf("/nOK, has matched .../n/n");

for (i = 1; i < rc; i++) {
substring_start = ((char *)TesTsSubj) + ovector[2*i];
int substring_length = ovector[2*i+1] - ovector[2*i];
//printf("%2d: %.*s/n", i, substring_length, substring_start);
// printf("Pattern: %s/n", substring_start);
substring_start[substring_length] = '\0';
}
RING_API_RETSTRING(substring_start);
// free(re);
// ******************************************************************************************

Philip Hazel

unread,
Apr 22, 2022, 3:48:47 AM4/22/22
to stefano cerbioni, pcre2-dev
1. You should be using PCRE2, not PCRE1, which is obsolete and no longer maintained.

2. Your code does not actually show what PatterN  or TestTsSubj contains, so it is impossible to comment. 

Regards,
Philip


--
You received this message because you are subscribed to the Google Groups "PCRE2 discussion list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pcre2-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pcre2-dev/CAAwR5B8HgvB4f9EG0sZOUOsNGCe1ZaXvkL974-y-KVPn-Y1OTg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages