07-1 虚幻引擎中使用正则表达式

虚幻引擎中使用正则表达式

模块与头文件

​ Core模块中,头文件为:Regex.h

#include “Regex.h"

表达式内容

FRegexPattern TestParrtern(TEXT("\^d{5,12}"));

查找

​ 使用FRegexMatcher类来完成对正则表达式的驱动。常用的是FindNext函数,返回一个bool值,表示是否查找到匹配的字符串。

FString TextStr("ABCDEFGHIJKLMN");
FRegexPattern TestPattern(TEXT("C.+H"));
FRegexMatcher TestMatcher(TestPattern, TextStr);
while(TestMatcher.FindNext())
{
UE_LOG(MyLog, Warning, TEXT("找到匹配内容 %d-%d"), TestMatcher.GetMatchBeginning(), TestMatcher.GetMatchEnding());
}