Open Schweber opened 5 months ago
How about a regex condition? Not that I disagree with adding the flag
$string =~ '\bsearchterm\b'
Ah thanks, i didn't know that i can do it this simply.
Many people forget that !~
and =~
are regex operators. You can see that with help operators
.
Related problem
I was exploring ways to check for the existence of a search term in a string consisting of several words in nu. I want to know if the search term matches one of the words in the string exactly.
However,
str contains
does not have a flag to match whole words likegrep -w
and i didn't find another nu command that can do what i want out-of-the-box.Describe the solution you'd like
I would like either 1)
str contains
to receive a flag that does a wordwise exact match 2) or another command that has this functionalityDescribe alternatives you've considered
I could do
find -r \bsearchterm\b
and check its output with an if statement or something like that. Or i could do$string | split row ' ' | any {$in == searchterm}
.It would be nice to have a simpler alternative to this though.