I am trying to match regardless of case.
regexp:RegExp pattern = re `(ax|test)is$`;
Should match both Axis or axis.
>Solution :
Use an inline modifier to your regex pattern:
regexp:regexp pattern = re `(?i)(ax|test)is$`;
The (?i) at the beginning does the trick of turning on case-insensitive mode for the entire pattern. Your code would functions like:
- (?i): Sets case-insensitive matching.
- (ax|test): This group matches either "ax" or "test".
- is$: Ensures the match ends with the letters "is".
An example mnight be:
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.isMatch(word1)) {
io:println("Match: " + word1);
}
if (pattern.isMatch(word2)) {
io:println("Match: " + word2);
}
if (pattern.isMatch(word3)) {
io:println("Match: " + word3);
}
}
This code will output:
Match: Axis
Match: axis
Match: TestiS