Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Pattern Matching with PCRE and SLRE

Ok,
I have been recently trying to do a pattern matching with regular expressions.I have to do this in C(No other language) .I have used slre library and wrote this:
Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "slre.h"
#include "slre.c"

int main(void)
{
    char* mystring = "potty <body class=\"admin-yokohoma admin-235\"> lovely baby :*";
    struct slre_cap caps[2];
    static const char* regex = "<body class=\".*(admin-).*(admin-).*\">";
    if(slre_match(regex,mystring, strlen(mystring), caps, 2, 1) > 0)
    {
        char buffer[100];
        printf("We have found it! Yay!\n");
        char* ptr = caps[0].ptr + 6;
        char* loc = strchr(ptr ,' ');
        int ttlsize = (int) (loc - ptr);
        printf("%d\n",ttlsize);
        strncpy(buffer,ptr,ttlsize);
        buffer[ttlsize] = '\0';
        printf("Matched:%s",buffer);
    }
}

This works fine for short string.But my problem is that I will have to check for this pattern in a whole web page source code about 60000 characters but unfortunately slre is not able to handle it for some reason.Whenever I use this code in that program to look for this pattern in webpage,It never ends.There is No Loops.The program doesn't terminate.And with smaller strings it is ok.But slow.

So I wanted to use PCRE.But I am not getting it how to use it.I tried downloading the library but pcre.h is not there.Can somebody show me how to use PCRE like this code.Starting from the download.Please I really need it.Or show me some other effective way to handle huge strings and matching patters please.

Best Regards.
Regex is not suited to parse SGML.
Try this XML parser, it's really lightweight and will run a LOT faste
hxxp://tibleiz.net/asm-xml/tutorial.html

Also see hxxp://stackoverflow.com/questions/6751105/why-its-not-possible-to-use-regex-to-parse-html-xml-a-formal-explanation-in-la
https://hackforums.net/showthread.php?tid=4553947 Don't make a new thread for the same problem.
(Nov 26, 2014 07:44 AM)-ceramic- Wrote:  Regex is not suited to parse SGML.
Try this XML parser, it's really lightweight and will run a LOT faste

hxxp://tibleiz.net/asm-xml/tutorial.html

Also see hxxp://stackoverflow.com/questions/6751105/why-its-not-possible-to-use-regex-to-parse-html-xml-a-formal-explanation-in-la

Thanks Bro for clearing all the confusions,
I have looked it up.But can you give me a sample code how to use it.I have huge string which contains html source.I want to look for that Specific string pattern and return its matches.Can you show me with Asm-Xml.I googled it I cound't find helpful examples.

Best Regards.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Legends] by itcorpJul 13, 2026 06:41 PM 7 395 Jul 13, 2026 06:41 PM
Last Post: CL1B
[Python] by PlutoPicksSep 24, 2020 07:50 PM 4 160 Sep 24, 2020 07:50 PM
Last Post: Lindros
[.NET] by PolaR01May 6, 2020 08:06 AM 3 174 May 6, 2020 08:06 AM
Last Post: Joel