सबएक्सप्रेशन/मेटाकैरेक्टर “\B” नॉन-वर्ड बाउंड्री से मिलान करता है।
उदाहरण 1
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
public static void main( String args[] ) {
String regex = "\\Bcause";
Scanner sc = new Scanner(System.in);
System.out.println("एक स्ट्रिंग दर्ज करें: ");
String input = sc.nextLine();
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
int count = 0;
while(m.find()) {
count ++;
}
System.out.println("मिलान की संख्या: " + count);
}
}
आउटपुट
एक स्ट्रिंग दर्ज करें: A sentence doesn't end with because because, because is a conjunction मिलान की संख्या: 3
उदाहरण 2
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main( String args[] ) {
System.out.println("इनपुट स्ट्रिंग दर्ज करें: ");
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
String regex = "\\B";
// रेगुलर एक्सप्रेशन संकलित करना
Pattern pattern = Pattern.compile(regex);
// Matcher ऑब्जेक्ट प्राप्त करना
Matcher matcher = pattern.matcher(input);
int count =0;
System.out.println("नॉन-वर्ड बाउंड्री: ");
while(matcher.find()) {
count ++;
}
System.out.println(count);
}
}
आउटपुट
इनपुट स्ट्रिंग दर्ज करें: Hello how are you welcome to Tutorialspoint नॉन-वर्ड बाउंड्री: 30