dlclark / regexp2

A full-featured regex engine in pure Go based on the .NET engine
MIT License
997 stars 84 forks source link

Support dotAll flag #83

Closed monkeyWie closed 4 months ago

monkeyWie commented 4 months ago

Thank you for this great project, but it seems that the dotAll option is not supported now, is there any way to achieve it?

dlclark commented 4 months ago

My understanding is that dotAll is a synonym for “regexp2.Singleline” option or (?s)

monkeyWie commented 4 months ago

Ya, but when I use regexp2.ECMAScript | regexp2.Singleline, it not work.

monkeyWie commented 4 months ago

Using regexp2.Singleline alone is fine.

dlclark commented 4 months ago

What exactly doesn't work? I'll need a regex, options, match text, and what you expected the match to be. I suggest the form of a unit test.

monkeyWie commented 4 months ago

Thanks for the quick reply, below is the unit test code:

// It works fine
func TestRegexpSingleline(t *testing.T) {
    re := regexp2.MustCompile(`.`, regexp2.Singleline)
    if isMatch, _ := re.MatchString("\n"); !isMatch {
        t.Fatal("Expected match")
    }
}
// It not work
func TestRegexpECMAScriptWithSingleline(t *testing.T) {
    re := regexp2.MustCompile(`.`, regexp2.ECMAScript | regexp2.Singleline)
    if isMatch, _ := re.MatchString("\n"); !isMatch {
        t.Fatal("Expected match")
    }
}

image

dlclark commented 4 months ago

This is now fixed -- the regex parser's if/elseif block was backwards for dot. Singleline should always include all chars and EcmaScript only has a different set for dot if Singleline isn't set.

Thanks for the report!

monkeyWie commented 4 months ago

I just upgraded to the latest version but still have problems. It seems that the latest submit only added a unit test

dlclark commented 4 months ago

Well that's embarrassing. My git add *.go missed that the change was in the syntax folder. Code now shipped.

monkeyWie commented 4 months ago

Thanks, it work well now!