Changes

Jump to: navigation, search

ULI101 Week 9

91 bytes added, 21:33, 4 November 2018
Asterisk '*'
Depending on the utility and its version, some versions support standard regular expressions and some support extended regular expressions. Although some of them may look like shell expansion characters they usually mean something else. Whenever you wish to match a special character literally it must be quoted.
== Period '<code>.</code>' ==
Period is the only wildcard in regular expressions (RE). The period character in a regular expression can be viewed as a placeholder (match) for any single character. Some examples of period being used in regular expressions:
|}
== Asterisk '<code>*</code>' ==
Represents zero or more occurrences of regular expression directly preceeding the asterisk (<code>*</code>). By itself, it does not match anything - it is NOT a wildcard. It is used in conjunction with literal matches, a period or other special characters. Some examples of asterisk in regular expressions:
| Will match
|-
| <code>/cartcar*/</code>
| car, carpool, cart, caret
|-
|}
== Square brackets '<code>[]</code>' ==
Enclose a character class or group, similar to the shell. Any single character within the brackets will be matched. Hyphen can be used for defining a range of characters. Most special characters lose their special meaning. The caret sign at the beginning of the list means exclusion (<code>[^a]</code> means ''do not match a''). Some examples of square brackets in regular expressions are:
|}
== Caret '<code>^</code>' ==
Matches strings at the beginning of the line (anchoring it). Special only if the beginning of the regular expression, otherwise means a literal match. Inside square brackets means character exclusion. Some examples of caret in regular expressions are:
|}
== Dollar '<code>$</code>' ==
Matches strings at the end of the line, (anchoring matches to the end of the line). Examples of dollar in regular expressions are:
|}
== Grouping '<code>()</code>' and grouping with alteration '<code>(|)</code>' ==
Parentheses can be used to create bracketed regular expressions. The parentheses group the regular expression inside. The parentheses are not matched, only what is inside. Grouping offers alteration/choice represented by the pipe (|). When a grouped expression is followed by a quantifier such as the asterisk, the quantifier applies to the entire group Examples of grouping with and without alteration are:
<blockquote><code>grep</code> requires the <code>-E</code> option to enable grouping
</blockquote>
 
= Search and Replace in vi =
572
edits

Navigation menu