0

In Ruby, when I match string like "12a" with regular expression /1(2)(a)/, I can find second and third chars in $1 and $2 variables. Like this:

"12a" =~ /1(2)(a)/
> $1
=> "2"
> $2
=> "a"

Can I make something like this in c++ Boost 1.37? I programming in Borland C++ 6, so last version of boost there works 1.37.0.

Michael
  • 548
  • 8
  • 30
  • 1
    Those are not called "backsequences". In Ruby they are called "parenthesized groups" or "captures". If you know the correct terminology you will more easily be able to find the answers to your questions by searching. – Mark Byers Oct 17 '12 at 12:04
  • 1
    They are called capturing group and they exist in boost's implementation too: http://www.boost.org/doc/libs/1_33_1/libs/regex/doc/captures.html – Martin Ender Oct 17 '12 at 12:06
  • This page may help you: http://www.boost.org/doc/libs/1_31_0/libs/regex/doc/syntax.html and more precisely the "Back references" section. –  Oct 17 '12 at 12:09
  • Thank you guys! Its exactly what I want. – Michael Oct 17 '12 at 12:19

1 Answers1

0

Yes, you can. Use library #include <boost/regex.hpp> for that.

See this example: C++ Regular Expressions with Boost Regex

Community
  • 1
  • 1
Ωmega
  • 42,614
  • 34
  • 134
  • 203