Closed freijon closed 3 weeks ago
If we added like
for a synonym to =~
we'd probably need to add not-like
for a synonym to !~
too. I wouldn't be against these changes.
I don't think it's good idea to add like
:
We can say 'm1cNnTsf2blMGiThe2beJnerh4xiA6mRy1NVjAY0VtULuOEX5BJWBiY6v0wi' =~ (or contains) '2'
, But can we say, as a matter of common sense, that m1cNnTsf2blMGiThe2beJnerh4xiA6mRy1NVjAY0VtULuOEX5BJWBiY6v0wi
like 2
, or vice versa?
BTW:
We already have str contains
command, you can also write ls | where name =~ .bash
as ls | where ($it.name | str contains '.bash')
My example was probably not the best, I use =~ with regex, which is not possible with str contains
. The operator like
would just say "use regex", like on SQL. It would be logical because nushell
uses several commands borrowed from SQL, like where
, select
.
find
works with regex:
ls | find -r .bash -c [name]
I agree it would be very nice to have a 'like' operator. Especially since nushell's ethos is about structured data. Leveraging existing syntax from tools like SQL/Pandas etc. when working with similar structures only makes it much easier for developers to pick up and go with minimal learning curve.
=~ or like !~ or not like
Related problem
The
~
character is awkward to write on certain keyboards (I need to hit three keys to insert it). Also, I often confuse the order and write~=
instead of=~
, but maybe that's just my brain that's wired wrong.Describe the solution you'd like
In SQL languages the
like
operator is used. I propose thatlike
could be used on top of=~
. The operators should work exactly the same, it's just another way to write it. An operator-alias if you like. The syntax would be very SQL-like.Example:
ls | where name like .bash
could be used instead ofls | where name =~ .bash
Describe alternatives you've considered
No response
Additional context and details
No response