HowTo: Use PCRE with Visual C++?

I want to use PCRE with Visual Studio 6/7/8. My understanding is the latest version of PCRE is 6.4 (but might be 6.6?)

PCRE seems mostly intended for Unix/Linux programmers. The developer seems to have little or no interest in providing nmake or VC++ project files (dsw, dsp, sln, vcproj). I've gotten errors trying to compile/link the pcre files with a demo.cpp file.

I would like a very simple program (with project files) that uses PCRE 6.4 (or later) to do the equivalent of:

// demo.cpp
#include "pcre.h"
#include <stdio.h>
void main(void) {
  char   str[] = "search within this string to find whether cat is contained";
  char   subStr[] = "cat";
  char   replaceStr[] = "dog";
  // pcre statement to search str;
  // pcre statement to replace cat with dog
  printf("%s\n", str);
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

To search you can use
char* posOfStr = strstr(str, subStr);
Modified code

void main(void) {
  char   str[100] = "search within this string to find whether cat is contained";
  char   tempStr[100];
  char   subStr[] = "cat";
  char   replaceStr[] = "dog";

  strcpy(tempStr, str);
  char* c = strstr(str, subStr);
  strcpy(c, replaceStr);
  char* c1 = strstr(tempStr, subStr);
  strcpy(c + strlen(replaceStr), c1 + strlen(subStr));

  printf("%s\n", str);
>> char   str[100] = "search within this string to find whether cat is contained";
Give a size to this array. Because if the replaceStr is big then you will get segmentation fault.
newton-allanAuthor Commented:
Sorry if my question wasn't clear. I know how to use strstr to find the string. That isn't the point of my question. I want to use the PCRE (Perl Compatible Regular Expressions) library to do match/replace that will be MUCH more complicated. The "cat" to "dog" example was just to illustrate.

PCRE library link:

The real match/replace is going to be something like Bible scripture references, which are of the form:
BookStringName chapNum:verseNum
so that something like the C/C++ search string:
char str[500] = "The Ten Commandments start at Exodus 20:3 and the Sermon on the Mount starts at Matthew 5:3 and the largest encoding would be Psalm 119:176.";

find: (PlaceHolder_0|Genesis|Exodus|Leviticus|...|Psalm|...|Malachi|Matthew|Mark|...|Revelation) ([0.9]{1,3}):([0-9]{1,3})
"The Ten Commandments start at <ref=2.20.3>Exodus 20:3</ref> and the Sermon on the Mount starts at <ref=40.5.3>Matthew 5:3<ref> and the largest encoding would be <ref=19.119.176>Psalm 119:176</ref>."

Exodus is the 2nd book, so the encoded reference becomes 2.20.3. Matthew is the 40th book, so the encoded reference becomes 40.5.3. Psalm is the 19th book, and so on.

It would have to find the pattern with a ##:## after it .... encountering just Exodus or just Matthew without the ChapNum:VerseNum pattern immediately after it wouldn't be considered a match.

My understanding is that RegEx was made for tasks such as these when strstr isn't adequate. The problem is getting PCRE to build for vc6 or vc7.1. The PCRE developer primarily supports Linux/Unix, and doesn't seem to have much interest in Windows developers.

Closed, 250 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.