J
J
Jsman2016-01-20 14:43:59
Java
Jsman, 2016-01-20 14:43:59

How to cut a string with a regular expression?

Good afternoon! There is a line
String valueUrl = getPage(" api.vk.com/method/database.getRegions?&country_id=1 ");
the cat contains the answer:

{"response":[{"region_id":"1000001","title":"Адыгея"},{"region_id":"1121540","title":"Алтай"},{"region_id":"1121829","title":"Алтайский край"},{"region_id":"1123488","title":"Амурская область"},{"region_id":"1000236","title":"Архангельская область"},

"It repeats so ad infinitum =) "
How to cut it with a regular expression so that there are only regions (and put them in an array)?
String[] urlRegexp = valueUrl.split(" ??? "); --- I do not understand what to prescribe here so that everything turns out as intended?
I tried , it worked for me, but with the id number and ":" , "," .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Oparin, 2016-01-20
@SeniorDmitry

If you really want a regular expression, then you can do something like:

String s = "та самая строка";
// коды
Matcher m = Pattern.compile("\"region_id\":\"(\\d+)\"").matcher(s);
while (m.find()) { m.group(1));}

// названия
Matcher m2 = Pattern.compile("\"title\":\"([^\"]+)\"").matcher(s);
while (m2.find()) { m2.group(1));}

A
Artem Vereschaka, 2016-01-20
@And3en

You receive data in JSON format. use any JSON reader for your PL and it will be much easier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question