minte9
LearnRemember



Class

Character class matches any one of serveral characters.
 
#!/bin/sh

: "Character class []
matches any one of several characters

For characters inside a class, the implication is OR
For chars outside a class, the implication is AND

Within a class, dash (-) means a range of chars
Multiple ranges are fine [0-9a-z]
"

A='gray grey greay greey gr-y'
B='<H1></H1> <H22></H22> <H3></H3>'

echo $A | grep 'gr[-ae]y' -o | tee result.txt
echo $B | grep '<H[1-3]>' -o | tee result.txt -a
 
gray
grey
gr-y
<H1>
<H3>

Javascript

 
/**
 * Character class []
 */

s1 = 'gray grey greay greey'
s2 = '<H1>aaa</H1> <H2>bbb</H2>'

p1 = /gr[ae]+y/g; // g AND r, a OR e, y 
p2 = /<H[1-6]>/ig;

m1 = s1.match(p1);
m2 = s2.match(p2);

console.log(m1); // gray, grey, greay, greey
console.log(m2); // H1, H2



  Last update: 187 days ago