Use regular expressions to configure the boost library in vc6.0

Source: Internet
Author: User
Tags regex expression
Recently, developers have encountered long string matching and search problems. The first thing they think of is the use of regular expressions, which is simple and efficient.

However, the development tool I used is vc6.0, which does not support regular expressions.

After surfing the internet with Baidu, I found that there are quite a few libraries that support regular expressions. There are probably the following types: boost, GNU, and vc7 in ATL and Greta released by Microsoft.

My friends on the Internet spoke well about boost and decided to use it!

1. Download the boost library and find it online. I downloaded a compressed package of over 20 MB, and nearly 100 MB after decompression.

The directory I extracted is D:/boost.

2. then compile. I only need to support regular expressions, so I only need to compile the files in the D:/Boost/libs/RegEx/build directory. It is said that it takes nearly two hours to compile all the regular expressions, which has not been verified. It takes less than five minutes to compile the regular expressions on my home machine.

One of the most articles about how to compile on the internet is "VC uses the boost library to parse regular expressions". If someone can follow this article to compile it successfully, tell the younger brother ......

Here are my operations:

Enter "cmd" in "run" to open the command prompt;

Enter the command "cd d:/Boost/libs/RegEx/build" // set the current directory

Enter the command "D:" // to the current directory

Next is a key step:
Many articles refer to "Input nmake-fvc6.mak"
However, "'nmake' is neither an internal or external command, nor a program or batch file that can be run ." Error message.
Then you will try your best to find the cause. In the result, another article says that the environment variables are not configured, and then a bunch of "sets" are given ".
Some articles say that it is OK to run the vc98/bin/vcvars32.bat file under the installation directory of Visual Studio.
As you have done by the author of the article, the problem persists!
The above statements are correct, but they are not completely complete. The root cause of the error prompt is that the environment variable is not configured properly and the nmake command is not recognized, users who have configured JDK are easy to understand. If we have a bunch of "sets" according to the author's requirements, we can solve the problem by simply using 'nmake' once.
Vcvars32.bat officially configures the batchcompute file for environment variables, but the configured parameters are only valid in the current window. That is to say, when you double-click it to close the window after running, the environment variables are no longer available.

So I used the following method:
Drag the vcvars32.bat file to the CMD window ("D:/program files/Microsoft Visual Studio/vc98/bin/VCV
Ars32.bat "), and then press Enter.

Enter the command "nmake-fvc6.mak"

Wait a few minutes. OK !, D:/Boost/libs/RegEx/build has a vc6 folder, which contains many lib and DLL files.

3. Now the resource is ready. The following task is to configure vc6.0 so that it can find the regular library during compilation.

Copy all lib and DLL files under vc6 to vc98/boostrex under the installation directory of Visual Studio (boostrex is created by myself)

Open vc6.0, select "tools-> options-> directories-> include files", and add a line "D:/Boost"

Select "tools-> options-> directories-> library file" and add a line "C: /program files/Microsoft Visual Studio/vc98/boostrex "(the color part is my Visual Studio installation directory)

The configuration is OK!

4. Write a program for testing

Test In SDK:

# Include "stdafx. H"
# Include <cstdlib>
# Include <stdlib. h>
# Include <boost/RegEx. HPP>
# Include <string>
# Include <iostream>

Using namespace STD;
Using namespace boost;

RegEx expression ("^ select ([A-Za-Z] *) from ([A-Za-Z] *)");

Int main (INT argc, char * argv [])
{
STD: String in;
Cmatch what;
Cout <"Enter test string" <Endl;
Getline (CIN, In );
If (regex_match (in. c_str (), what, expression ))
{
For (INT I = 0; I <What. Size (); I ++)
Cout <"str:" <what. STR () <Endl;
}
Else
{
Cout <"error input" <Endl;
}
Return 0;
}

Input: Select name from table
Output: Str: Select name from table
STR: Name
STR: Table

Test in MFC (note the following when there are several points ):

Create an MFC project in the dialog box,
Add header file
# Include <boost/RegEx. HPP>

Click the button and add it to the Event Response Function.
Boost: RegEx expression ("^ select ([A-Za-Z] *) from ([A-Za-Z] *)");
Cstring in = "select GM from tab ";
Cstring sret;
Boost: cmatch what;
If (boost: regex_match (lpcstr (in), what, expression) // cstring to string
{
For (INT I = 0; I <What. Size (); I ++ ){
Sret = (what . STR (). c_str ();// Convert string to cstring
MessageBox (sret );
}
}
Else
{
MessageBox ("error input ");
}

The output result is the same as above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.