Any page from Wikipedia :
... abas asdn asf asfs af {{Template1 |a = Name surname |b = jhsdf sdf |c = {{Template2}} |d = |e = [[f]] and [[g]] |h = asd asdasfgasgasg asgas jygh trdx dftf xcth |i = 73 |j = {{Template2|abc|123}} |j = {{Template3|aa=kkk|bb={{Template4|cc=uu}}}} }} asd wetd gdsgwew g {{OtherTemplate |sdf = 213 }} ...
How can I find Template1 content (start |a end is }} ) with Java regular expressions?
I tried:
String pattern = "\\{\\{\\s*Template1\\s*(.*?)\\}\\}"; Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); Matcher m = p.matcher(content); while (m.find()) { if (!m.group().equals("")) { System.out.println(m.group()); System.out.println("-----------------------"); } }
But here the regex finds the first }} (which is Template2 }} ) and then stops.
I want to pass }} any {{ open. Then I want to find a match with my parents.
I want to get the top Template1 content between the vertices {{ and }} ?.
EDIT:
Note that after removing the spaces, I parse the content .
content.replaceAll("\\s+","");
Think of the content as writing one line.
java string regex match wikipedia
Marspeople
source share