(Created page with "<seo title="Regular Expressions Basics | vEdit" description="Learn the many characters that have special meaning in the search string of regular expressions and how to use th...") |
(→Related Resources) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 19: | Line 19: | ||
:Matches zero or one occurrences of the preceding character (or list). In other words, the preceding character is optional. | :Matches zero or one occurrences of the preceding character (or list). In other words, the preceding character is optional. | ||
| − | + | ==Examples of Using Regular Expressions== | |
;o.e | ;o.e | ||
| Line 80: | Line 80: | ||
The syntax allows exceptions where the “\” is not needed, but in those cases the “\” does not hurt either, and we recommend using it in front of all non-alphanumeric characters within search strings. In the replacement string, only the two characters “\” and “&” are special symbols. | The syntax allows exceptions where the “\” is not needed, but in those cases the “\” does not hurt either, and we recommend using it in front of all non-alphanumeric characters within search strings. In the replacement string, only the two characters “\” and “&” are special symbols. | ||
</div> | </div> | ||
| + | |||
| + | ==Related Resources== | ||
| + | *[[Regular_Expressions|Regular Expressions Overview]] | ||
| + | *[[Special_Matching_Characters|Special Matching Characters]] | ||
| + | *[[Special_Matching_Characters#The_OR_Operator|The “OR” Operator]] | ||
| + | *[[Groups_Replacement_Strings|Groups and Replacement Strings]] | ||
| + | *[[Groups_Replacement_Strings#Groups_and_Replacement_Examples|Groups and Replacement Examples]] | ||
| + | *[[Regular_Expressions_Newline|Matching the “Newline”]] | ||
| + | *[[Maximize_Regular_Expression|Maximize Regular Expression Matching]] | ||
To use regular expressions, be sure that the option ( )Reg-Exp is selected in the Search/Replace dialog box.
Many characters have special meaning in the search string of regular expressions:
Think of “*” as indicating that one or more occurrences of the previous character are “optional”. Notice that ann*e is identical to an+e
A list of characters within square brackets [ and ] matches any one character in that list. A range of characters can be abbreviated using a hyphen “ - ”. However, when the first character in the list is a “ ^ ” (caret) or “ ~ ” (tilda), the list matches any character, except those in the list.
The [ ]Case search option is applicable to regular expressions, but not within bracketed lists. Therefore, “hi” will match “HI”, “Hi”, etc., and the expression [a-z]i will match “hi” and “hI”, but not “Hi”. There is little reason to ever select the [ ] Case option — you could use the expression [h][i] to search for the lower case word “hi”.
A “\” followed by any character (except a digit or letter), simply matches that character. This allows searching for those characters which are used as special symbols in regular expressions. Although we recommend using the “\” in front of any special symbols you need to search in the text, the “\” is not needed when there is no possibility of confusion. For example, the characters {, }, |, * and + are not special within the square brackets. The $ is only special at the very end of the expression. Even the hyphen “-” is not special immediately following [ or preceding ] or outside of square brackets.
These characters are special symbols in regular expressions, and therefore must be preceded by “\” in order to search for them in the text:
^ $ . * + ? - ~ \ | [ ] { }
The syntax allows exceptions where the “\” is not needed, but in those cases the “\” does not hurt either, and we recommend using it in front of all non-alphanumeric characters within search strings. In the replacement string, only the two characters “\” and “&” are special symbols.