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

Conditional operator for NOT match regex? #2416

Open
laniakea64 opened this issue Oct 6, 2024 · 2 comments
Open

Conditional operator for NOT match regex? #2416

laniakea64 opened this issue Oct 6, 2024 · 2 comments

Comments

@laniakea64
Copy link
Contributor

I have run into a number of cases where a "not matching regex" condition would be useful, i.e. the opposite of =~. Latest example is here: without a "not matching regex" conditional operator, this check cannot use assert() which was specifically designed for cases like this.

Does just have such operator? If not, could it please be added?

BTW I'm not finding the documentation of the assert() function-like expression in the README?

@Montana
Copy link

Montana commented Oct 21, 2024

So @laniakea64,

As of now, "just" does not natively support a "not matching regex" operator directly. However, you can usually achieve a similar effect using existing logical operations. Here’s a common workaround using negation (!) and =~::

if !(some_string =~ r"some_regex") {
  # Code to execute if the string does NOT match the regex
}

Alternatively, the issue might be suggesting a feature request to add a specific !~ or similar operator to make this more intuitive, but this does not seem to be implemented yet.

As for the assert() function, it’s likely being used to validate that certain conditions are true. If you’re not finding it in the documentation, it might be a less-documented feature or related to the specific environment or context the user is working with. Hopefully this helps you.

Cheers,
Montana.

@casey
Copy link
Owner

casey commented Oct 30, 2024

I think we should add !~. This seems common enough that it's useful, and you can't really work around with negation, since conditionals are a grammar-level hack.

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

3 participants