Regex 101: Difference between revisions
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
echo "AAAAAAAAAAAB" |grep "^A*B$ | echo "AAAAAAAAAAAB" |grep "^A*B$ | ||
</syntaxhighlight> | |||
==Word Boundries== | |||
Was not sure what this meant but what it means is a word in a sentence e.g. quick brown fox so this would be a match | |||
<syntaxhighlight lang="bash"> | |||
echo "quick brown fox jumps over" |grep "\bfox\b" | |||
</syntaxhighlight> | |||
And this would not be a match | |||
<syntaxhighlight lang="bash"> | |||
echo "quick brownfoxjumps over" |grep "\bfox\b" | |||
echo "quick brown foxjumps over" |grep "\bfox\b" | |||
echo "quick brownfox jumps over" |grep "\bfox\b" | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 03:16, 11 April 2021
Testing
echo "My stuff" | grep "^My"
Examples
Starts with
echo "A" |grep "^A"
echo "AAAAAAAAAAA" |grep "^A"
Starts with any number of As and Ends With
echo "AAAAAAAAAAAB" |grep "^A*B$
Word Boundries
Was not sure what this meant but what it means is a word in a sentence e.g. quick brown fox so this would be a match
echo "quick brown fox jumps over" |grep "\bfox\b"
And this would not be a match
echo "quick brownfoxjumps over" |grep "\bfox\b"
echo "quick brown foxjumps over" |grep "\bfox\b"
echo "quick brownfox jumps over" |grep "\bfox\b"
Match Start and End with anything in the middle
Look like \b is the better approach to ^ and $
echo "AxxxxxxxB" |grep "\b\A\w*B\b"