Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issue with NKo Digits #47

Closed
tschaub opened this issue Mar 29, 2022 · 2 comments
Closed

Compatibility issue with NKo Digits #47

tschaub opened this issue Mar 29, 2022 · 2 comments

Comments

@tschaub
Copy link

tschaub commented Mar 29, 2022

It looks like \d matches ߀ (\u07c0) with regexp2, but not with the standard library regexp.

See the following example:

package main

import (
	"fmt"
	"regexp"

	"github.com/dlclark/regexp2"
)

func main() {
	re := regexp.MustCompile(`^\d$`)
	re2 := regexp2.MustCompile(`^\d$`, regexp2.RE2)

	notZero := "߀" // \u07c0

	match := re.MatchString(notZero)
	fmt.Printf("regexp: %v\n", match)

	match2, _ := re2.MatchString(notZero)
	fmt.Printf("regexp2: %v\n", match2)
}

Perhaps this is a known issue, but I'm wondering if there is a way to get additional compatibility with the standard library.

@tschaub
Copy link
Author

tschaub commented Mar 29, 2022

I missed the regexp2.ECMAScript option. Looks like compiling with this option is what I'm after. Thanks for the work on this library.

@tschaub tschaub closed this as completed Mar 29, 2022
@dlclark
Copy link
Owner

dlclark commented Mar 29, 2022

No problem. The ECMAScript option does change the character classes to match ECMAScript/JavaScript and it just so happens that ECMAScript \d and \w matches the same chars as Go's RE2 engine. However, \s does not contain the exact same chars in RE2 and ECMAScript.

It makes sense to use the RE2 char class definitions for all 6 (\s \w \d plus negates) if option RE2 is used. Forcing the ECMAScript option isn't ideal.

Thanks for bringing it up.

@dlclark dlclark reopened this Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants