EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH
Regular Expressions
Some commands allow selection of items via "regular expression" strings.
Such a pattern string must be enclosed in single or double quotes.
MAD-X follows regexp (Unix regular expression patterns) for matching.
The following features are implemented:
A "search string" below is the string containing the pattern, a "target
string" is the string being searched for a possible match with the pattern.
- "^" at the start of the search string:
Match following search string at the start of the target string; otherwise
the search string can start anywhere in the target string. To search for a
genuine "^" anywhere, use "\^".
- "$" at the end of the search string:
Match preceding search string at the end of the target string; otherwise
the search string can end anywhere in the target string. To search for a
genuine "$" anywhere, use "\$".
- ".":
Stands for an arbitrary character; to search for a genuine ".", use "\."
- "[xyz]":
Stands for one character belonging to the string contained in brackets
(example: "[abc]" means one of a, b, c).
- "[a-ex-z]":
Stands for ranges of characters
(example: "[a-zA-Z]" means any letter).
- "[^xyz]" (i.e. a "^" as first character in a square bracket):
Stands for exclusion of all characters in the list, i.e. "[^a-z]"
means "any character but a lower case letter".
- "*":
Allows zero or more repetitions of the preceding character, either specified
directly, or from a list.
(examples: "a*" means zero or more occurrences of "a",
"[A-Z]*" means zero or more upper-case letters).
- "backslash-c" (e.g. "\."):
Removes the special meaning of character c.
All other characters stand for themselves.
Example:
select,flag=twiss,pattern="^d..$" ;
select,flag=twiss,pattern="^k.*qd.*\.r1$" ;
The first command selects all elements whose names have exactly three
characters and begin with the letter "D".
The second command selects elements beginning with the letter "K",
containing the string "QD", and ending with the string ".R1".
The two occurrences of ".*" each stand for an arbitrary
number (including zero) of any character,
and the occurrence "\." stands for a literal period.
hansg,
May 8, 2001