main.cpp

来自「正则表达式由一些普通字符和一些元字符(metacharacters)组成。普通字」· C++ 代码 · 共 67 行

CPP
67
字号
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#include <locale.h>
#include "LytWString.h"
#include "Link.h"
#include "OrderedLink.h"
#include "Tree.h"
#include "Set.h"
#include "GrammarTree.h"
#include "CharClass.h"
#include "StatusEdge.h"
#include "EpsilonNfa.h"
#include "Nfa.h"
#include "Dfa.h"
#include "Matrix.h"
#include "DfaMatrix.h"
#include "Regex.h"

using namespace std;

void main(int argc , char* argv[])
{
	setlocale(LC_ALL,"chs");

	while(true)
	{
		LytWString Expression;
		wcout<<L"请输入正则表达式(exit结束) : ";
		wcin>>Expression;
		if(Expression==L"exit")
		{
			break;
		}
		Regex ExpressionRegex(Expression);
		if(ExpressionRegex.IsError())
		{
			wcout<<ExpressionRegex.GetErrorMessage()<<endl;
		}
		else while(true)
		{
			LytWString Content;
			wcout<<L"请输入所要匹配的字符串(exit结束) : ";
			wcin>>Content;
			if(Content==L"exit")
			{
				break;
			}
			Regex::MatchResult Result=ExpressionRegex.Match(Content.Buffer());
			if (ExpressionRegex.IsError()==0)
			{
				int len1=wcslen(Content.Buffer())-wcslen(Result.Start);
				int len2=Result.Length;
				int len3=wcslen(Content.Buffer())-len1-len2;
				wcout<<Content.Sub(0,len1)<<L"【"<<Content.Sub(len1,len2)<<L"】"<<Content.Sub(len1+len2,len3)<<endl;
			}
			else
			{
				wcout<<ExpressionRegex.GetErrorMessage()<<endl;
			}
		}
		wcout<<endl;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?