minte9
LearnRemember / REGEX



Optional

Question mark in u? means u optional.
 
#!/bin/sh

: "Optional items
Question mark in colou?r means u optional
It is placed after the character that is optional
Grouping for optional, is one of the main uses of parantheses
"

A='color colour colur colou semicolon'
B='4 4th 4th?'

echo $A | grep 'colou?r' -o -E | tee result.txt
echo $B | grep '4(th)?'  -o -E | tee result.txt -a
 
color
colour
4
4th
4th






Questions and answers




A regex containing optional metacharacter is always successful? [b,2]

  • a) yes
  • b) no

What is one of the main uses of parantheses? [b,2]

  • a) grouping for negative
  • b) grouping for optional

Which character is optional in colou?r

  • a) u
  • b) r


References