0

I have been looking up places to work with regex in c++ , as I want to learn regular expressions in c++ (do give me a step by step link also if you guys have any). I am using g++ to compile my programs and working in Ubuntu. earlier my program were not compiling but then I read this post where it said to compile the program by "g++ -std=c++0x sample.cpp" to use the regex header. My first program works correctly, i tried implementing regex_match

#include<stdio.h>
#include<iostream>
#include<regex>
using namespace std;

int main()
{
string str = "Hello world";
regex rx ("ello");

if(regex_match(str.begin(), str.end(), rx))
{ 
cout<<"True"<<endl;
}
else
cout<<"False"<<endl;
return(0);
}

for which my program returned false ... ( as the expression is not matching completely) I also rechecked it by making it match...it works. Now I am writing another program to implement regex_replace and regex_search . Both of which doesnt work ( for regex_search just replace regex_match in the above program with regex_search. kindly help.I dont know where I am getting wrong.

2
  • 1
    You show us code that you say works correctly, then ask us about why other code doesn't work, but you don't show us that code. Can you think of something that might help us guess what's wrong with that other code? Commented Jan 1, 2013 at 23:57
  • i told you just replace regex_match with regex_search .. the latter should return true but its not ... Commented Jan 2, 2013 at 0:00

1 Answer 1

2

The <regex> header is not fully supported by GCC.

You can see GCC support here.

Sign up to request clarification or add additional context in comments.

4 Comments

so what should be the solution then ? I have to stop working with GCC to use regex then ?
@Worlock Visual Studio 2012 supports <regex>, and you also have boost regex.
thanks for the information Rapptz ,but I want to use GCC , and is boost regex for GCC ? if yes can you give me the guide to install boost and make it compatible with gcc .
@Worlock boost is just a library you can get here, just link it like you would any library. Most of its components are header only, they have a guide for setting up boost there though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.