无论大小写,我都试图匹配。
regexp:RegExp pattern = re `(ax|test)is$`;
Run Code Online (Sandbox Code Playgroud)
应匹配 Axis 或 axis。
小智 4
对正则表达式模式使用内联修饰符:
regexp:regexp pattern = re `(?i:(ax|test)is$)`;
Run Code Online (Sandbox Code Playgroud)
开头(?i:...)的技巧是为整个模式打开不区分大小写的模式。你的代码的功能如下:
一个例子可能是:
import ballerina/io;
import ballerina/regexp;
public function main() {
regexp:RegExp pattern = re `(?i:(ax|test)is$)`;
string word1 = "Axis";
string word2 = "axis";
string word3 = "TestiS";
if (pattern.isFullMatch(word1)) {
io:println("Match: " + word1);
}
if (pattern.isFullMatch(word2)) {
io:println("Match: " + word2);
}
if (pattern.isFullMatch(word3)) {
io:println("Match: " + word3);
}
}
Run Code Online (Sandbox Code Playgroud)
该代码将输出:
Match: Axis
Match: axis
Match: TestiS
Run Code Online (Sandbox Code Playgroud)