#RegEx help

4 messages · Page 1 of 1 (latest)

fiery nova
#

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?

jade ridgeBOT
#

This post has been reserved for your question.

Hey @fiery nova! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fiery nova