0

I am having trouble understanding following grep operation

a=jQuery.Uno echo $a | grep -i "jquerya*" 

why is above query returning jQuery.Uno?

1 Answer 1

1

The * quantifier matches 0 (zero) or more.

In the string, jQuery.Uno there is 0 a after y. As such, the regex jquerya* matches the string.

If you wanted one or more of a, then instead say:

grep -i "jquerya\{1,\}" 

or, if your version of grep supports extended regular expressions:

grep -iE "jquerya+" 

Moreover, instead of echo "$var" | grep ..., it is better to make use of herestrings if your shell supports those:

grep -iE "jquerya+" <<< "$a" 
Sign up to request clarification or add additional context in comments.

1 Comment

@MarkSetchell Thanks for fixing the typos.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.