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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C and Regular Expressions

  • 05-02-2009 2:24pm
    #1
    Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭


    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,584 ✭✭✭✭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