Answer the question
In order to leave comments, you need to log in
How to search in a string by Russian pattern in Java?
I immediately apologize for the trivial question, I am new to Java. There is a set of strings like this:
Arctikot|data.28.xml|3029
Arktogeya|data.84.xml|3898
Arlov|data.90.xml|19
Armavir|data.23.xml|
628 there definitely is:
cat|data.1.xml|4132
I'm looking for this:
while ((str = in.readLine()) != null) {
//keyword - текст "кот"
if (str.matches("^"+keyword+"\\|")){
....
}
}
Answer the question
In order to leave comments, you need to log in
str.matches is the same as Pattern.compile(regexp).matcher(str).matches()
In your case, as you rightly said above, you need to find. In general, str.startsWith("cat") is also suitable for you.
String s = "кот|data.1.xml|4132";
Pattern pattern = Pattern.compile("^" + "кот" + "\\|");
Matcher matcher = pattern.matcher(s);
System.out.println(matcher.find());
String.matches returns true if the string is completely described by the regular expression. "cat|" does not match "cat|data.1.xml|4132". Add an asterisk at the end:
str.matches("^кот\\|*")
There are some inconveniences in Java when working with regular expressions and text containing Unicode (read Cyrillic).
read here for more details: stackoverflow.com/questions/4304928/unicode-equivalents-for-w-and-b-in-java-regular-expressions
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question