Is it the boost library? Regex in particular? I have searched and searched, but this is all I could come up with.

If this is the correct library, then how do I get it to work in Dev-C++? I managed to add all the boost .h files to my Dev-C++ include files folder, so now it will compile when I #include a boost header file.

Does it even work in Dev-C++ though? I couldn't get it installed properly in Visual Studio. I think the path name was not quite right (to include the boost root directory).

Also, how do you use the regcomp() function? I've seen examples where it takes more than one argument, however in the regexp.h file (that came with boost) it lists only one argument. Here is the header file I am trying to use:

/*
 * Definitions etc. for regexp(3) routines.
 *
 * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
 * not the System V one.
 */
#ifndef REGEXP_DWA20011023_H
# define REGEXP_DWA20011023_H

#define NSUBEXP  10
typedef struct regexp {
	char *startp[NSUBEXP];
	char *endp[NSUBEXP];
	char regstart;		/* Internal use only. */
	char reganch;		/* Internal use only. */
	char *regmust;		/* Internal use only. */
	int regmlen;		/* Internal use only. */
	char program[1];	/* Unwarranted chumminess with compiler. */
} regexp;

regexp *regcomp( char *exp );
int regexec( regexp *prog, char *string );
void regerror( char *s );

/*
 * The first byte of the regexp internal "program" is actually this magic
 * number; the start node begins in the second byte.
 */
#define	MAGIC	0234

#endif

And here is one example program I found online, that I can't get compiled as yet, I think because the header file they used was not boost's regexp but another regex .h file. And yes, I know it's C, but I want to do this in C++.

#include <iostream>
#include <regexp.h>//I changed the header to the one I have
#include <locale.h> 

using namespace std;


int main()
{
    //regcomp("help");
/* CELEBR07                                      

   This example compiles an extended regular expression.                        

 */                                                                             
    unsigned int MAX_MATCH = 10;
regexp re; //I changed the type here
char *pattern = ".*";                
regmatch_t pmatch[MAX_MATCH];
regcomp(&re, pattern, REG_ICASE|REG_EXTENDED|REG_NOSUB);
regexec(&re, "This is a test", MAX_MATCH, pmatch, 0);                                                                 
                                                            
    char       *string = "a simple string";                                     
    char       *pattern = ".*(simple).*";                                       
    int        rc;                                                              
                                                                                
    if ((rc = regcomp( string))!=0 ) {                     
       printf("regcomp() failed, returning nonzero (%d)", rc);
         system("Pause");                 
       exit(1);                                                                 
    }                                                                           

}

Any hints/suggestions/shove in the right direction would be much appreciated! :)

Dani AI

Generated

Short summary and practical fix: for modern C++ prefer the standard <regex> API (std::regex, added in C++11). Boost.Regex remains a solid, feature‑rich alternative (historically used before C++11); recent Boost releases make Boost.Regex usable in a header‑only mode for C++11+ compilers. As observed, older Boost builds required linking a separate library, but that requirement changed as Boost modernized. (cppreference.net)

Cause of the compile errors in the thread: the pasted header is the old V8/Henry Spencer style regexp.h (the regcomp in that API returns a regexp *), which is different from the POSIX <regex.h> API (POSIX regcomp takes a regex_t * and returns an int). Mixing those incompatible APIs (V8-style, POSIX C, Boost, and C++ std::regex) explains the mismatched signatures and compile failures — pick one API and use its matching headers and functions. (groups.google.com)

Recommendations and toolbox:

  • If the toolchain supports C++11 or later, switch to #include <regex> or to <boost/regex.hpp> from a modern Boost release.
  • If portability and Perl-like features are required, consider Boost.Regex or a dedicated PCRE/PCRE2 port instead of std::regex.
  • Note that some std::regex implementations (libstdc++) have had bugs/regressions historically, so validate on the actual compilers/standard libraries targeted. (gcc.gnu.org)

Minimal std::regex example (C++11+):

#include <regex>
#include <string>
#include <iostream>

std::regex r("(simple)");
std::smatch m;
if (std::regex_search(std::string("a simple string"), m, r))
    std::cout << m[1] << '\n';

On Windows, older Dev‑C++ bundles an out‑of‑date MinGW; upgrading the toolchain (MinGW‑w64/MSYS2 or a recent Visual Studio) or using a modern IDE will avoid many C++11/Boost headaches. Mention of : the posted regexp.h is the V8 variant, so replacing that include with either <regex.h> (POSIX) or <regex>/<boost/regex.hpp> and adjusting calls to the chosen API resolves the signature mismatch.

I think you would have better luck in a forum dedicated to Boost and/or Regex questions. One thing I can suggest is that the Boost Regex has to be linked to its binaries too (boost_regex.lib or libboost_), so make sure that is set up correctly (if not you should get loads of "unresolved external reference" errors). Also, we have seen here many people with weird problems with Dev-C++, so consider either giving it another go with VS or installing Code Blocks instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.