Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C and Regular Expressions

Options
  • 05-02-2009 3:24pm
    #1
    Registered Users Posts: 26,579 ✭✭✭✭


    I'm looking to preform some regular expressions from within a C program.

    I'm only used to doing regexes in perl and php so I'm not too up with doing them in C.

    I found how to do them using the "regex.h" header but I've heard this doesn't work in windows due to regex.h use of the GNU Regex library which is only supported in unix.

    The program will be used on windows but at the moment i'm coding on unix so i can't test if the above is true or not.

    What's the best way to use regular expressions in a C program, or is there one? I've tried google but it's one of those google searches that the words I put in don't bring me to relevant results.

    I know I could write a perl file to perform the regular expression, write the matches i need to a temp file and read those in the C program, whilst I'm not striving for efficency that would make a meal out of the process especially if there's another (easier) way.


Comments

  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    If you want to stick with a purely windows compiler, then yer bang out of luck. You've two choices really: use a third party library or write a regex parser yourself. How complex is your regex?

    The MingW (windows port of gcc + gnu utils) may be of use, they may (and I'm not sure if they do) support the regex() function. So maybe this might work for you, if you can get away with using this compiler.


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    What im doing is reading a C program file line by line in a c program and i want tthe regex to capture write() system calls and list them on screen.

    I don't have a lot of time to muck about with any compilers other than gcc and it's not imperative that it works with windows but it would be handy


  • Registered Users Posts: 2,013 ✭✭✭SirLemonhead


    For something like that, surely you could read through each line, detect the presence of "write(" then keep printing until a semi colon is found?


  • Registered Users Posts: 163 ✭✭stephenlane80


    The MingW (windows port of gcc + gnu utils) may be of use, they may (and I'm not sure if they do) support the regex() function. So maybe this might work for you, if you can get away with using this compiler.

    This MingW contains the POSIX regex library so it should work, you could compile it to a MingW executable in cygwin with the

    following command :g++ -mno-cygwin

    you must have both gcc,g++ and MingW librarys installed in cygwin to work


Advertisement