Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convet Perl regular expression to equivalent ECMAScript regular expression

Convet Perl regular expression to equivalent ECMAScript regular expression

Scheduled Pinned Locked Moved C / C++ / MFC
linuxtoolsregexc++perl
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Falconapollo
    wrote on last edited by
    #1

    Now I'm using VC++ 2010, but the

    syntax_option_type

    of VC++ 2010 only contains the following options:

    static const flag_type icase = regex_constants::icase;
    static const flag_type nosubs = regex_constants::nosubs;
    static const flag_type optimize = regex_constants::optimize;
    static const flag_type collate = regex_constants::collate;
    static const flag_type ECMAScript = regex_constants::ECMAScript;
    static const flag_type basic = regex_constants::basic;
    static const flag_type extended = regex_constants::extended;
    static const flag_type awk = regex_constants::awk;
    static const flag_type grep = regex_constants::grep;
    static const flag_type egrep = regex_constants::egrep;

    It doesn't contain

    perl_syntax_group

    (Boost Library has the option). However, I don't want to use the Boost Library. There are many regular expression written in Perl, So I want to convert the existing Perl regular expressions to

    ECMAScript

    (or any one that VC++ 2010 support). After conversion I can use the equivalent regular expressions directly in VC++ 2010 without using the third party libray. One example:

    const boost::tregex e(__T("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"));
    const CString human_format = __T("$1-$2-$3-$4");
    CString human_readable_card_number(const CString& s)
    {
    return boost::regex_replace(s, e, human_format);
    }
    CString credit_card_number = "1234567887654321";
    credit_card_number = human_readable_card_number(credit_card_number);
    assert(credit_card_number == "1234-5678-8765-4321");

    In the above example, what I want to do is convert e and format to ECMAScript style expressions. ECMA Script regex is a subset of Perl regex, if I don't use the features exclusive to Perl regex. **Is it possible to find a general way to convert all Perl regular expressions to

    ECMAScript

    style?** Are there some tools to do this? Any help will be appreciated!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups