A
A
askalidov2022-03-30 09:52:08
Java
askalidov, 2022-03-30 09:52:08

How to split a string in a certain way?

There is a string like:
"from lowerRange to upperRange y", where lowerRange and upperRange can be of different lengths.
It is necessary to output 2 substrings - lowerRange and upperRange
For example, input:
"from 124 871 to 252 676 ye", respectively output:
"124 871", "252 676"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-03-30
@askalidov

Pattern pattern = Pattern.compile("от ([0-9 ]+) до ([0-9 ]*[0-9])");
Matcher matcher = pattern.matcher("от 124 871 до 252 676 уе");

if (matcher.find()) {
    System.out.println(matcher.group(1));
    System.out.println(matcher.group(2));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question