Answer the question
In order to leave comments, you need to log in
How to parse text or number by mask into Android Studio variable?
There is a line: <div class="blockk">Free memory: 29568 b.<br><hr>
I want to get a variable with a value of 29568 b
Using a type mask <div class="blockk">Free memory: (.+?).<br><hr>
I don't know how to implement this. I read about regular expressions, in all examples the comparison and the result is false or true, but how to pull out the value you need, I did not find examples, tell me where to read?
Answer the question
In order to leave comments, you need to log in
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches
{
public static void main( String args[] ){
// Строка, которую будем парсить
String line = "<div class=\\"blockk\\">Free memory: 29568 b.<br><hr>";
// Наша регулярка
String pattern = "<div class=\\"blockk\\">Free memory: (.+?).<br><hr>";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(line);
// Если нашли то выводим
while (m.find( )) {
System.out.println("Found value: " + m.group(0) );
} else {
System.out.println("NO MATCH");
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question