Can someone help me understand how to use PCRE with C++?

This is a discussion on Can someone help me understand how to use PCRE with C++? within the C++ Programming forums, part of the General Programming Boards category; I am a beginner to C++, working on Win 7 x64. I've got myself set up with MinGW and Visual ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    11

    Can someone help me understand how to use PCRE with C++?

    I am a beginner to C++, working on Win 7 x64. I've got myself set up with MinGW and Visual Studio 2010.

    I would like to use PCRE for RegEx, but I have no idea how to install it to work with these two compilers. I tried to research this, but the people who write PCRE are upfront about knowing nothing about Windows, and so don't provide much assistance. And what little information I can find is clearly written for experienced programmers, and is not easily understood by someone new.

    Is there anyone familiar with this who can help walk me through the process of setting up PCRE 8.12 with MinGW and Visual Studio?

    Alternately, if a good guide exists, you can just point me in the right direction. But so far, I haven't been able to find anything appropriate.


    Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,981
    Quote Originally Posted by KenLP
    Is there anyone familiar with this who can help walk me through the process of setting up PCRE 8.12 with MinGW and Visual Studio?

    Alternately, if a good guide exists, you can just point me in the right direction. But so far, I haven't been able to find anything appropriate.
    The compiler that comes with Visual Studio 2010 comes with the TR1 extensions to the standard library, including the regular expressions library. The functionality provided by <regex>, which is soon to be included in the C++ standard, to be ratified later this year. A quick search brings up this tutorial on Getting started with C++ TR1 regular expressions, and you should be able to test with this program:
    Code:
    #include <iostream>
    #include <regex>
    #include <string>
    
    int main()
    {
        using namespace std;
        string str = "Hello world";
        tr1::regex rx("ello");
    
        if (regex_match(str.begin(), str.end(), rx))
        {
            cout << "Match" << endl;
        }
        else
        {
            cout << "No match" << endl;
        }
    
        if (regex_search(str.begin(), str.end(), rx))
        {
            cout << "Found" << endl;
        }
        else
        {
            cout << "Not found" << endl;
        }
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    Thanks, but I'm looking to use PCRE specifically.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,981
    Unless you really do need certain PCRE specific syntax, it seems that the ECMAScript option will be good enough for you.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    Quote Originally Posted by laserlight View Post
    Unless you really do need certain PCRE specific syntax, it seems that the ECMAScript option will be good enough for you.
    ECMAScript, to my knowledge, is equivalent to JavaScript RegEx, which is extremely limiting. PCRE is significantly more capable, as far as RegEx is concerned, and from what I was able to find, far outstrips TR1 in terms of performance.

    Thus, PCRE is what I'm looking to use. I'm asking how to use it.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    ...far outstrips TR1 in terms of performance...
    o_O
    Outstrips which TR1 implementation?
    I'd be careful with such statements since every compiler vendor can implement it differently.
    Unless PCRE has a lower time complexity than TR1, such statements are dangerous.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  7. #7
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    Quote Originally Posted by Elysia View Post
    o_O
    Outstrips which TR1 implementation?
    I'd be careful with such statements since every compiler vendor can implement it differently.
    Unless PCRE has a lower time complexity than TR1, such statements are dangerous.
    My apologies if I was incorrect. I was working off of this:

    August 2008 Software Ramblings

    It compares PCRE with vc9_fp1 and vc9_sp1, and there is no comparison between them.


    That being said, the issues of RegEx capability alone is enough for me to need PCRE, so that's still what I'm looking to use. If I can figure out how.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    Unless you can get a MinGW maintainer to do it for you, you might have to do this yourself (though they may offer some guidance - join their mailing lists and forums).

    PCRE - Perl Compatible Regular Expressions leading to Pcre for Windows
    One thing you could do there is compare the "pcre" release with the MinGW port of it, to see what was actually involved. Hopefully, the changes should be minimal.

    Following that, you might try to emulate those changes with the latest "pcre" release and port that to the latest MinGW. Again, the MinGW maintainers should be able to advise.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    Quote Originally Posted by Salem View Post

    Unless you can get a MinGW maintainer to do it for you, you might have to do this yourself (though they may offer some guidance - join their mailing lists and forums).

    PCRE - Perl Compatible Regular Expressions leading to Pcre for Windows
    One thing you could do there is compare the "pcre" release with the MinGW port of it, to see what was actually involved. Hopefully, the changes should be minimal.

    Following that, you might try to emulate those changes with the latest "pcre" release and port that to the latest MinGW. Again, the MinGW maintainers should be able to advise.

    The latest version of PCRE is 8.12. The Windows port is 7.0. That's far too behind for me.

    That's why I was asking about how to work with the full version in its standard form. I'll try asking the MinGW folks, but I'm not sure anyone there is going to be able to help me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me to understand
    By rits in forum C Programming
    Replies: 5
    Last Post: 10-15-2009, 11:58 AM
  2. I don't understand this
    By Dontgiveup in forum C++ Programming
    Replies: 14
    Last Post: 03-28-2009, 07:04 PM
  3. help me understand...
    By stormfront in forum C Programming
    Replies: 2
    Last Post: 10-12-2005, 10:47 AM
  4. Can't understand FAQ
    By Vorkosigan in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2004, 02:37 AM
  5. i cant understand this!!
    By thongsai in forum C++ Programming
    Replies: 4
    Last Post: 04-18-2003, 09:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21