I've a number of subscription from a YouTube
channel that I copied.
It's "4 372 236"
.
I'm testing the "\s+"
regex on https://regex101.com for that number and it does not work. When i'm writing the same number on my own the regex does work. Anybody knows what's wrong?.
I'm trying to remove the white space chars from such numbers but i cannot do it. I tried also the .replaceAll(" ", "")
method but does not work neither.
The JSON Youtube code: JSON Youtube
Then I'm using JSON library
to get the subscriptions like this:
JSONObject jsonObject = new JSONObject();
jsonObject = new JSONObject(content);
JSONArray tabs = jsonObject.getJSONObject("contents")
.getJSONObject("twoColumnBrowseResultsRenderer")
.getJSONArray("tabs");
JSONObject tabRenderer = tabs.getJSONObject(5).getJSONObject("tabRenderer");
JSONObject sectionListRenderer = tabRenderer.getJSONObject("content").getJSONObject("sectionListRenderer");
JSONArray contents2 = sectionListRenderer.getJSONArray("contents");
JSONObject itemSectionRenderer = contents2.getJSONObject(0).getJSONObject("itemSectionRenderer").getJSONArray("contents").getJSONObject(0);
JSONObject channelAboutFullMetadataRenderer = itemSectionRenderer.getJSONObject("channelAboutFullMetadataRenderer");
String subs = channelAboutFullMetadataRenderer.getJSONObject("subscriberCountText").getJSONArray("runs").getJSONObject(0).getString("text");
And finally, i'm using the regex
to delete the whitespaces from number:
subs = subs.replaceAll("\\s+", "");
System.out.println(subs);
I tried this too but it does not work. I think it's not a regular space but I don't know how to recognise it.
subs = subs.replaceAll(" ", "");