IDE regular expressions/fr: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: IDE regular expressions/fr
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Normal regular expression | |
| 2 | + | ||
| 3 | + | Metacharacters: | |
| 4 | + | ``` | |
| 5 | + | \ Quote the next metacharacter | |
| 6 | + | ^ Match the beginning of the line | |
| 7 | + | . Match any character (except newline). Example: 'a.c' matches 'abc', 'aBC', 'axc', 'a3c', 'a$c', etc. | |
| 8 | + | $ Match the end of the line (or before newline at the end) | |
| 9 | + | | Alternation | |
| 10 | + | () Grouping. For example: (abc)+ matches 'abc' or 'abcabc' or 'abcabcabc' etc. | |
| 11 | + | [] Character class. For example [abc], [a-z], [a-zA-Z0-9_] | |
| 12 | + | [^] Reversed character class. For example [^a-z] | |
| 13 | + | ``` | |
| 14 | + | ||
| 15 | + | Quantifiers: | |
| 16 | + | ``` | |
| 17 | + | * Match 0 or more times | |
| 18 | + | + Match 1 or more times | |
| 19 | + | ? Match 1 or 0 times | |
| 20 | + | {n} Match exactly n times | |
| 21 | + | {n,} Match at least n times | |
| 22 | + | {n,m} Match at least n but not more than m times | |
| 23 | + | ``` | |
| 24 | + | ||
| 25 | + | Curly brackets in any other context is treated as a regular character. The ``*_is equivalent to {0,}, the ``+_ to {1,} and the ``?_to {0,1}._ | |
| 26 | + | ||
| 27 | + | By default, a quantifier is _greedy_ , that means, it will match as many times as possible. To match the minimum number of times possible, append a ``?_._ | |
| 28 | + | ``` | |
| 29 | + | *? Match 0 or more times | |
| 30 | + | +? Match 1 or more times | |
| 31 | + | ?? Match 0 or 1 time | |
| 32 | + | {n}? Match exactly n times | |
| 33 | + | {n,}? Match at least n times | |
| 34 | + | {n,m}? Match at least n but not more than m times | |
| 35 | + | ``` | |
| 36 | + | ||
| 37 | + | ## Simple Syntax | |
| 38 | + | ||
| 39 | + | Some IDE dialogs provide a checkbox to enable 'simple syntax'. These regular expressions are shorter for common file name filters. | |
| 40 | + | ||
| 41 | + | Technically it does this: | |
| 42 | + | ``` | |
| 43 | + | The following characters are replaced with | |
| 44 | + | . -> \. | |
| 45 | + | * -> .* | |
| 46 | + | ? -> . | |
| 47 | + | , -> | | |
| 48 | + | ; -> | | |
| 49 | + | ||
| 50 | + | Finally enclose by ^( )$ | |
| 51 | + | ``` | |
| 52 | + | ||
| 53 | + | ## Quoted symbols | |
| 54 | + | ||
| 55 | + | The backslash '\' can be used to treat special characters like '.' as normal character or to get some special ranges. | |
| 56 | + | ``` | |
| 57 | + | \. matches a point '.' | |
| 58 | + | \d matches a number character '0'..'9' | |
| 59 | + | \D matches a non number character | |
| 60 | + | \s matches a space character ' ',#9,#10,#12,#13 | |
| 61 | + | \S matches a non space character | |
| 62 | + | \w matches a word character 'a'..'z','A'..'Z','0'..'9','_' | |
| 63 | + | \W matches a non word character | |
| 64 | + | \b word boundary | |
| 65 | + | \B not word boundary | |
| 66 | + | \A begin of line | |
| 67 | + | \Z end of line | |
| 68 | + | ``` | |
| 69 | + | ||
| 70 | + | ## Search and Replace with regular expressions | |
| 71 | + | ||
| 72 | + | The find dialogs support regular expressions for finding and replacing. Each found pattern grouped in round brackets can be used by a $1, ..., $9 variable | |
| 73 | + | ||
| 74 | + | For example: | |
| 75 | + | ||
| 76 | + | * Find expression: a(.*)c | |
| 77 | + | * Replace expression: A$1C | |
| 78 | + | * Text: 'abc aLazc' | |
| 79 | + | ||
| 80 | + | The $1 will be replaced with the found text, that matches the first bracket. | |
| 81 | + | ||
| 82 | + | * Result: 'AbC ALazC' | |
| 83 | + | ||
| 84 | + | --- | |
| 85 | + | *From the Free Pascal wiki, page "IDE regular expressions/fr", as the Internet Archive kept it on 2020-10-31, last changed on 2007-06-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
