LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-06-2006, 04:55 AM   #1
indian
Member
 
Registered: Aug 2004
Posts: 137

Rep: Reputation: 15
Do we have regular expression in C++ ?


Hi,

I am looking to make a program in C++ which will be greatly solved by using regular expressions. Does C++ have default support of regular expression(i.e. inbuilt library) or do I need to get some external library to use it ? I am working on DevC++,windows by the way.A example will be really helpful.

Regards
 
Old 03-06-2006, 05:26 AM   #2
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
Well, I haven't used it for myself so far, but I know that the great "boost-library" (http://www.boost.org) offers a class for regular expressions. This library is also known to be very good documented, so you will surely get along with it.
http://www.boost.org/libs/regex/doc/index.html
 
Old 03-06-2006, 08:53 AM   #3
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
There's also a C way to do it -- man 3 regex . I'd imagine the boost library makes it look better
 
Old 03-06-2006, 09:33 AM   #4
indian
Member
 
Registered: Aug 2004
Posts: 137

Original Poster
Rep: Reputation: 15
Hi, I have installed Boost for VC6 and refered to some online code. I have already added the library for VC6 and the code is giving me the following error:fatal error C1083: Cannot open include file: 'boost\function.hpp': No such file or directory All the paths are fine I guess..what can be the problem than.I hope asking such questions do not violate policies of LQ


Code:
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
using namespace std;
int main () {
  
  int i;
  string str="hello world";

  static const boost::regex e("hello world");
   i=regex_match(s, e);
   if(i!=1)
	   cout << "not matched";
  return 0;
}
 
Old 03-06-2006, 09:54 AM   #5
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
Are you sure, that your paths are correct? It looks to me, that you didn't add the boost directory (that contains the headers) to your include paths. So look where "boost\function.hpp" is located on your system and add this directory (the one that contains the "boost" subdirectory) to your include paths. It's a long time ago, since I last worked with VC6, but you should find these paths-settings somewhere under the menu Options/Projects/Directories/Include, or something similar.

EDIT:
Oh, and you should also add
Code:
#include <boost/regex.hpp>
And change the "s" (first parameter of 'regex_match') to "str". After doing so, the program worked fine for me. And don't forget to link against the boost regex library.

Last edited by Flesym; 03-06-2006 at 10:31 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with regular expression aecaudel Programming 6 11-04-2005 05:28 AM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 08:13 AM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 10:08 AM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM
regular expression gumby Programming 3 07-15-2003 12:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration