Answers for "regex count occurrences"

0

regex count for matching in java

import java.util.regex.*;

class Test {
    public static void main(String[] args) {
        String hello = "HelloxxxHelloxxxHello";
        Pattern pattern = Pattern.compile("Hello");
        Matcher matcher = pattern.matcher(hello);

        int count = 0;
        while (matcher.find())
            count++;

        System.out.println(count);    // prints 3
    }
}
Posted by: Guest on September-26-2020
0

count matches with regex

use regex::Regex;

fn main() {
// count matches with regex
let re = Regex::new(r"(?i)th").unwrap();
let result = re.find_iter("The three truths.").count();
println!("result = {}", result);  // 3
}
Posted by: Guest on June-29-2021

Code answers related to "regex count occurrences"

Browse Popular Code Answers by Language