Basically, I'm reading information from the Wikipedia API, which returns JSON code containing the source code for a page in their markdown. I used a JSON API to filter what I want from the page, and now I want to format the text in a way that removes all the links and such.
The markdown displays links like this: [[wiki page|display text]]
But it can also display like this: [[wiki page]]
So, what I'm trying to do is extract the display text
if the pipe character exists, but if not I just want the wiki page
text.
This is my code for that right now, which should detect if there's a pipe character and handle those strings properly but doesn't:
private static String format(String s) {
return s.replaceAll("\\[\\[.+?(\\]\\]|\\|)", "").replace("[[", "").replace("]]", "").trim();
}
When running this it will sometimes take out any text that displays as simply [[wiki page]]
, but it works if the pipe character is there. How do I manage to get this working correctly?