आप जावा रेगेक्स में एक से अधिक स्पेस कैरेक्टर से कैसे मेल खाते हैं?जावा रेगेक्स: एक या अधिक स्पेस वर्णों से कैसे मिलान करें
मेरे पास एक रेगेक्स है जिसे मैं मिलान करने की कोशिश कर रहा हूं। रेगेक्स विफल रहता है जब मेरे पास दो या दो से अधिक स्पेस वर्ण होते हैं।
public static void main(String[] args) {
String pattern = "\\b(fruit)\\s+([^a]+\\w+)\\b"; //Match 'fruit' not followed by a word that begins with 'a'
String str = "fruit apple"; //One space character will not be matched
String str_fail = "fruit apple"; //Two space characters will be matched
System.out.println(preg_match(pattern,str)); //False (Thats what I want)
System.out.println(preg_match(pattern,str_fail)); //True (Regex fail)
}
public static boolean preg_match(String pattern,String subject) {
Pattern regex = Pattern.compile(pattern);
Matcher regexMatcher = regex.matcher(subject);
return regexMatcher.find();
}
'मानक मानक पैटर्न' => स्ट्रिंग पैटर्न 'जावा मानक कोडिंग सम्मेलनों में। – assylias
क्या है ... जावा कोड में PHP वाक्यविन्यास? – ean5533
यह हो सकता है कि दूसरी जगह का मिलान किया जा सके [^ a] (एक स्थान एक 'ए' नहीं है) – erikxiv