minte9
LearnRemember



Quantifiers

Metacharacter + means one or more of the immediately-preceding item.
 
#!/bin/sh

: "Quantifiers:
Metacharacter + means one or more of the preceding item
Metacharacter * means any (none or more), which is similar to the ?

Notation {0,1} is the same as ?
When single number is given, such as [a-z]{3}, 
it matches exactly that many
"

A='<H1> <H2> <H3 > <H7>'
B='
<HR SIZE=14>
<HR  SIZE = 14 >
<HRSIZE=14>
'

echo $A | grep '<H[1-6] *>'               -o -E | tee result.txt
echo $B | grep '<HR +SIZE *= *[0-9]+ *>'  -o -E | tee result.txt -a
 
<H1>
<H2>
<H3 >
<HR SIZE=14>
<HR SIZE = 14 >

More Examples

 
#!/bin/sh

: "Quantifiers:
Correct php variable names
Strings with double quotes
Time of the day, such as 9:17 AM
"

A='$a, $_b, $C, but not $1a'
B='"abc", but not "abc d'
C='
09:17 am
99:99 pm
9:17 am
12:30 pm
'

echo $A | grep '\$[a-zA-Z_][a-zA-Z_0-9]*'               -o -E | tee res2.txt
echo $B | grep '"[^"]*"'                                -o -E | tee res2.txt -a
echo $C | grep '\<(1[012]|[1-9]):[0-5][0-9]\> (am|pm)'  -o -E | tee res2.txt -a
 
$a
$_b
$C
"abc"
9:17 am
12:30 pm



  Last update: 364 days ago