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

REGEX operator only matches characters at the beginning of a string #207

Open
rolodato opened this issue Aug 22, 2024 · 2 comments
Open

Comments

@rolodato
Copy link
Member

REGEX is implemented using Pattern.match, which only checks the beginning of the search string:

If zero or more characters at the beginning of string match this regular expression, return a corresponding Match

This means a regular expression like world will not match a trait value of hello-world.

We should be using Pattern.search instead: https://docs.python.org/3.11/library/re.html#re.Pattern.search

@khvn26
Copy link
Member

khvn26 commented Aug 22, 2024

I'm leaning towards closing this issue as a wontfix:

  1. Such a change would be breaking for all SaaS customers.
  2. re.search is significantly less performant.
  3. A pattern like .*world should cater for the described use case, unless I'm missing something.

@rolodato
Copy link
Member Author

I can confirm using a pattern like .*world.* works, thanks for that suggestion!

There is probably a better way than using Pattern.search, it was the first thing that came to mind :)

I would argue this is a bugfix and not a breaking change. We don't document this specifically, but I would say the expectation for "matches regex" is essentially the same way grep behaves. grep world does match hello-world-hello, and does not require adding anything else around world to match.

We have this assumption built-in to every SDK that I've checked so far.

Node.js

> 'hello-world-hello'.match(/world/)
[ 'world', index: 6, input: 'hello-world-hello', groups: undefined ]

Ruby

irb(main):001> 'hello-world-hello'.match?('world')
=> true

Golang

package main

import "regexp"

func main() {
	matched, err := regexp.Match(`world`, []byte(`hello-world-hello`))
	println(matched, err)
	// true, nil
}

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