I am making .md editor and trying to recognize line of source that indicates h1 tag. This is my bit:
public static String mdFile = new Scanner(Downmark.class.getResourceAsStream("./res/elements_test.md"), "UTF-8").useDelimiter("\\A").next();
public static String decode(String mdString) {
String[] lines = mdString.split("\n");
String line = lines[0];
System.out.println("lines read: "+ lines.length);
System.out.println("System.out.println(line); :: " + line);
boolean matches = header_regex.matcher(line).matches();
System.out.println(matches);
return "";
}
elements_test.md file contains samples of different elements like so:
# Heading1
## Heading2
---
*italic*
**BOLD**
`monospace`
~~Strikethrough~~
output:
lines read: 92
System.out.println(line); :: # Heading1
false
when testing Pattern header_regex against line with Pattern.matches() resulting boolean is always false, but when I use Pattern.find() result is true. I understand differences between find and matches, but difference between result does not make sense to me. Can somebody explain?