Navigation Menu

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

Can regular expression be used in Conditional Expressions? Any string functions available? #959

Closed
meicale opened this issue Sep 6, 2021 · 6 comments · Fixed by #970
Closed

Comments

@meicale
Copy link

meicale commented Sep 6, 2021

I want to test whether a sub-string (such as "GPU") is contained in a parameter or values.
I tried if "GPUS" == "GPU", which can work in the shell and return the 'true' value.

@casey
Copy link
Owner

casey commented Sep 6, 2021

This isn't currently possible, but I think it would be a useful feature. I would propose adding it as a new conditional form, probably something like:

x := if foo ~= "bar" { a } else { b }

Where "bar" is a regex. We could also add slash-delimited regex literals, /…/, but I can't think of any strong advantages over just reusing string literals for this specific case, and adding regex literals if we need them later.

@meicale
Copy link
Author

meicale commented Sep 6, 2021 via email

@hustcer
Copy link
Contributor

hustcer commented Sep 12, 2021

I need this feature, too. Thx

@casey
Copy link
Owner

casey commented Sep 16, 2021

Implemented in #970! I'll try to cut a release soon, but for now it's available on master on GitHub.

The operator is =~ since that's what's used in Perl, Ruby, and other similar languages:

foo := if "hello" =~ 'hel+o' { "match" } else { "mismatch" }

bar:
  @echo {{foo}}
$ just bar
match

@casey
Copy link
Owner

casey commented Sep 29, 2021

I just published 0.10.2, which includes regular expression conditionals. Prebuilt binaries should be available soon on the releases page. Sorry for the delay! I was on vacation 🙇‍♂️

@meicale
Copy link
Author

meicale commented Sep 29, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants