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. tr1::regex

tr1::regex

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdelphiregex
4 Posts 3 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.
  • S Offline
    S Offline
    sashoalm
    wrote on last edited by
    #1

    I need a quick example on how to use tr1::regex class from VS2008. I have a string like "something" "something" ... and I want to get only what's between the first quotes. In VC6 find/replace it would look Find: "\([^"]\)" Replace: \1

    There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

    S S 2 Replies Last reply
    0
    • S sashoalm

      I need a quick example on how to use tr1::regex class from VS2008. I have a string like "something" "something" ... and I want to get only what's between the first quotes. In VC6 find/replace it would look Find: "\([^"]\)" Replace: \1

      There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

      S Offline
      S Offline
      Software_Developer
      wrote on last edited by
      #2

      Try Namespace: System::Text::RegularExpressions

      #using <System.dll>

      using namespace System;
      using namespace System::Text::RegularExpressions;
      int main()
      {

      Regex^ rx = gcnew Regex( "\\b(?<word>\\w+)\\s+(\\k<word>)\\b",static_cast<RegexOptions>(RegexOptions::Compiled | RegexOptions::IgnoreCase) );

      String^ text = ""something" "something"";
      MatchCollection^ matches = rx->Matches( text );
      Console::WriteLine( "{0} matches found.", matches->Count );

      for each (Match^ match in matches)
      {
      String^ word = match->Groups["word"]->Value;
      int index = match->Index;
      Console::WriteLine("{0} repeated at position {1}", word, index);
      }
      }

      http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^]

      S 1 Reply Last reply
      0
      • S Software_Developer

        Try Namespace: System::Text::RegularExpressions

        #using <System.dll>

        using namespace System;
        using namespace System::Text::RegularExpressions;
        int main()
        {

        Regex^ rx = gcnew Regex( "\\b(?<word>\\w+)\\s+(\\k<word>)\\b",static_cast<RegexOptions>(RegexOptions::Compiled | RegexOptions::IgnoreCase) );

        String^ text = ""something" "something"";
        MatchCollection^ matches = rx->Matches( text );
        Console::WriteLine( "{0} matches found.", matches->Count );

        for each (Match^ match in matches)
        {
        String^ word = match->Groups["word"]->Value;
        int index = match->Index;
        Console::WriteLine("{0} repeated at position {1}", word, index);
        }
        }

        http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^]

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        I don't thing he's referring to managed code. See TR1[^] here.

        Steve

        1 Reply Last reply
        0
        • S sashoalm

          I need a quick example on how to use tr1::regex class from VS2008. I have a string like "something" "something" ... and I want to get only what's between the first quotes. In VC6 find/replace it would look Find: "\([^"]\)" Replace: \1

          There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          TR1's regex is based on Boost[^]'s Regex[^] library. See the sample presented here[^], for example. You may have to alter the namespace and #include, but that should be about all.

          Steve

          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