Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C and Regular Expressions

  • 05-02-2009 03:24PM
    #1
    Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭


    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, Registered Users 2 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, Registered Users 2 Posts: 26,449 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 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