code:regular_expressions
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | code:regular_expressions [2006/07/16 19:44] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SED ====== | ||
+ | ===== Substrings ===== | ||
+ | Using Substrings, you can reuse parts of the expression to match for the replacement. This is a simple example: | ||
+ | $ date | ||
+ | Mon Jul 25 23:59:40 CEST 2005 | ||
+ | | ||
+ | $ date | sed -n 's/.*\ \(.*\)/ | ||
+ | 2005 | ||
+ | Important parts are: | ||
+ | | **-n** | do not output anything not requested | ||
+ | | **\(** | marks the beginning of the Substring | ||
+ | | **\)** | marks the end of the Substring | ||
+ | | **\1** | matches the first Substring defined in the expression | | ||
+ | | **/p** | print the substitution | ||
+ | ===== Order of Evaluation ===== | ||
+ | Strangely, the order of evaluation of Regular Expressions works from right to left. The simple example below proofs this: | ||
+ | $ release=`uname -r` | ||
+ | | ||
+ | $ echo $release | ||
+ | 2.6.12-gentoo-r6 | ||
+ | | ||
+ | $ expr $release : ' | ||
+ | 2.6 | ||
+ | | ||
+ | $ expr $release : ' | ||
+ | 2 | ||
+ | | ||
+ | $ expr $release : ' | ||
+ | 2.6 | ||
+ | | ||
+ | $ expr $release : ' | ||
+ | 2.6.12-gentoo-r6 | ||
+ | Clearly to be seen, the " |
code/regular_expressions.txt · Last modified: 2006/07/16 19:44 by 127.0.0.1