The [[awk]] programming language provides a set of *regular expression operators* that have special meanings within [[regular expression]]s. == _Regular Expression Binding Operators_ The *regular expression binding operator* applies the the right hand operand as a regular expression to the left hand operand and return a truth value depending on whether or not a match was found. * ~ Returns a value of true if the regular expression matches the left hand operand. {{{ BEGIN { text = "I like banana milkshake" if (text ~ /banana/) { print "Match found" } } }}} Negation can be achieved by combining the regular expression binding operator with a logical not operator: {{{ if (text !~ /strawberry/) { print "Match not found" } }}} == _A binding operator is not required when a regular expression is used as a pattern within a rule_ A binding operator is not required if a regular expression is being used as a pattern within a rule: {{{ # There is no binding operator when a regular expression is used as a pattern /rhubarb/ {print $0} }}} === _Substitution cannot be performed with binding operators_ Note that the regular expression binding operators cannot perform substitution to the left hand operand: {{{ # This will not work $text = "I like banana milkshake" if (text ~ s/banana/chocolate/) { print "Substitution made" print text } }}} == _Basic Regular Expression Operators_ | *Char* | *Name* | *Purpose* | ^ | [[caret]] | Anchor matches the beginning of a string | $ | [[dollar]] | Anchor matches the end of a string | . | [[dot]] | Matches any single character including a newline == _Extended Regular Expression Operators_ | *Char* | *Name* | *Purpose* | + | [[plus]] | The [[plus]] operator matches an operator or character at least once | ? | [[hook]] | The [[hook]] operator matches an operator or character either once or not at all
Summary:
This change is a minor edit.
Username: