So now I have this method:
public static String convert(String str) {
if (str.equals("# "))
System.out.println(" ");
Pattern pattern = Pattern.compile("(#+[^#]+)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
String str1 = matcher.group(1);
int n = str1.length() - str1.replaceFirst("#+", "").length();
System.out.println("<h" + n + ">" + str1.substring(n) + "</h" + n + ">");
}
return ("");
}
When I type ###Le Monde # it gives me < h3>Le Monde < /h3> < h1> < /h1>. I would like it to ignore the # following “le monde”. Basically, I want the algorithm to ignore a series of # followed by a space or return key. What am I doing wrong?
Add another line after getting the next match (str1), so:
That will ignore any whitespaces matches.