Funduc
Software Search and Replace Scripts |
Deutsch |
Search & Replace has extensive support for Regular Expressions for advanced search &/or replace, where the search string follows a rule and is not always exactly the same. Regular Expressions use "special character operators," which are symbols that control the search, and "an expression," which is a combination of characters and operators that specifies a pattern. Regular Expressions can be used in replacements, they can be case sensitive, and they can use Binary Characters or special operators such as Counters, Insert Path & File Name, & environment variables. NOTE: Take a look at our Regular Expression Wizard. For new and advanced users alike. If you are new to 'regular expressions', the Wizard is a good way to learn and experiment. Advanced users will find the tool helpful for debugging. Regular expressions are supported using a subset of the UNIX grep notation for Searching and DOS style Batch %n input parameter notation, with some extensions, for Replacing. The major differences between the Search and Replace and egrep regular expressions are: a) the . operator is not supported and b) *+?! operator must precede an expression enclosed by () or [] (such as *[123] or +(Windo.com), otherwise, the operator is assumed to match any/all characters from beginning of line or to the end of the line. Here you'll find some examples of Search & Replace's Regular Expression functions, including Search Match Operators, Search Sub-Expression Operators, Search
Literals, Some Basic Search Examples, Replacement Match Operators, Replacement Literals,
Search & Replacement Examples, Counter Operations, & Inserting the Path & File in Replacement Operations. Please see the
program's online help for more details and additional examples |
Regular Expression Search - Match Operators | |||||||||||||||||||||
Operator | Description | ||||||||||||||||||||
* |
|
||||||||||||||||||||
+ |
|
||||||||||||||||||||
? |
|
||||||||||||||||||||
! |
|
||||||||||||||||||||
! |
|
||||||||||||||||||||
^ |
|
||||||||||||||||||||
$ |
|
||||||||||||||||||||
^^ |
|
||||||||||||||||||||
$$ |
|
Top | Search & Replace Features | Search & Replace Page
Regular Expression Search - Subexpression Operators | |||||||||||||||||||
Operator | Description | ||||||||||||||||||
[] |
|
||||||||||||||||||
() |
|
||||||||||||||||||
+n |
|
Top | Search & Replace Features | Search & Replace Page
Special Search Characters (Literals) | |
- + * ? ( ) [ ] \ | $ ^ ! | If you wish to search for any of these characters, they must be preceded by the character to be interpreted as a literal in a search. |
Top | Search & Replace Features | Search & Replace Page
Some Example Regular Expression Search Operations | ||
What to Match | Operator | Effect |
Any single character | ? | g?t finds get, got, gut |
Any string of characters (one or more) | + | w+e finds wide, white, write but not we |
Any string of characters (or none) | * | w*e finds wide, white, write and we |
One of the specified characters | [] | g[eo]t finds get and got but not gu |
One of the characters in a range | [-] | [b-p]at finds bat, cat, fat, hat, mat but not rat or sat |
All characters | [] | i[] finds line, list, late |
One expression or another | (|) | W(in|indows) will find Win or Windows |
One or more expressions | +() | +(at) will find atat in catatonic and at in battle |
All characters (perhaps on different lines) | *[] | h[]d finds helped, Hello World, and Hello (cr lf) Win95 World. /\**[]\*/ will match C style comments (on several lines if necessary (*[] will span across multiple lines up to 32767 characters) |
A string that doesn't start with an expression | !() | : !(http) finds : in "following:" but not in "http://www.funduc.com"
Note: Syntax for pre-3.1 versions would be !(http): |
One of the characters not in a range | ![-] | [a-z]at!([b-p]at) matches r in "rat" & s in "sat" but nothing in "bat", "cat", "hat".
Note: Syntax for pre-3.1 versions would be ![b-p]at |
An expression at the beginning of a line | ^ | ^the finds the at the beginning of a line and The (if case sensitive is turned off) |
An expression at the end of a line | $ | end$ finds end when its the last string on a line. |
One or more column(s) before or after a string | +n | [h]+4// finds http:// but not https:// |
Using Special Characters | \ | \(\*\) will find (*) |
Top | Search & Replace Features | Search & Replace Page
Regular Expression Replacements - Match Operators | ||||||||||||||||||||||||||||||||||
Operator | Description | |||||||||||||||||||||||||||||||||
%n |
Core replacement operators use a %n convention, where n corresponds to a component in the regular expression search string. For example, %1 refers to the first expression value in the search string, %2 refers to the second, and so on. The %n parameters may be used several times, omitted, or used in any order. Up to 24 parameters may be used at once by referring to those over number %9 moving up the ASCII table, e.g., 123456789:;<=>?@ABCDEFGH. However, if your search-replace involves a large number of parameters you may find it easier to use a multi-step script.
In this example:
These parameters can be used several times, omitted or used in any order. |
|||||||||||||||||||||||||||||||||
< | Make lower case operator. To be used in conjunction with %n, e.g., %1< will replace the original first matched expression with its lower case version. | |||||||||||||||||||||||||||||||||
> | Make upper case operator. To be used in conjunction with %n, e.g., %1> will replace the original first matched expression with its upper case version. | |||||||||||||||||||||||||||||||||
%n> | Counter Operator. When used in conjunction with numeric regular expression search (e.g., *[0-9]), %n> begins incrementing with a value of +1 from the value of the first number found by *[0-9]. For example:
|
|||||||||||||||||||||||||||||||||
%n>#> | Counter Operator. This operator allows you to specify a starting value for an incrementing replacement counter. %n>starting value> begins incrementing with a value of +1 from the starting value you supply. This counter operator also respects the number of digit
places you supply. To begin incrementing with a value of 1, use the expression %n>0>. The expression %n>000> would begin replacements with a a value of 001. Another example is:
|
Top | Search & Replace Features | Search & Replace Page
Special Regular Expression Replacement Characters (Literals) | |
% \ < > | If you wish to replace any of these characters, they must be preceded by the character to be interpreted as a literal in a replacement. |
Top | Search & Replace Features | Search & Replace Page
Regular Expression Search & Replacement Examples | ||
Search Expression |
Replacement Expression |
Effect |
*.* | %1>.%2> | c:\windows\win.ini ==> C:\WINDOWS\WIN.INI |
+[a-z] | %1> | Windows ==> WINDOWS |
7*.htm | 5%1.htm | 711.htm ==> 511.htm 7days.htm ==> 5days.htm |
[253]7[832].htm | %15%2.htm | 3572.htm ==> 3552.htm |
*[253]7[832].htm | %15%2.htm | 72.htm ==> 52.htm |
(homepage|index).htm | %11.htm | homepage.htm ==> homepage1.htm index.htm ==> index1.htm |
+(12)[0-9] | %1%2a | 12532 ==> 12532a 1212753 ==> 1212753a |
???*(d|m).htm | %1%2%3d1.htm | card.htm ==> card1.htm form.htm ==> form1.htm |
back2.jpg*[]height="30" | back2.jpg%1height="32" | A multiline Search/Replace changing the height setting for 'back2.jpg' regardless of differing 'alt' text or how the html editor line breaks the code, e.g., src="images/back2.jpg" alt="Go Back" border="0" width="57" height="30" Becomes: src="images/back2.jpg" alt="Go Back" border="0" width="57" height="32" |
?(Windows) | OS/2 | Windows ==> OS/2 (just kidding) |
Top | Search & Replace Features | Search & Replace Page
Regular Expression search & replace Counter Operations allow you to quickly revise a sequence of numbers in one or more files. You can also insert sequential numbers to text strings where no numbers exist originally. Counter operations make use of *[0-9] regular
expression search operator and either the %n> or %n>user defined starting value> regular expression replacement operators.
The %n> replacement operator begins incrementing by one with a value of +1 from the value found by your *[0-9] expression (e.g.*[0-9]+1). The %n>user defined starting value> replacement operator increments by one beginning with a value of (user defined
starting value+1). This counter operator also respects the number of digit places you supply. Incrementing counter operations may be combined with other regular expression search & replace operators. For example, a search expression such as (file|variable)*[0-9] with a counter
replacement expression such as %1%2>100> is perfectly legal.
|
Top | Search & Replace Features | Search & Replace Page
Special Replacement Operators - %%srpath%% & %%srfile%% |
||||||||||||||||||||||||||||||||||||||||||
Search and Replace currently has two special replacement operators - %%srpath%% and %%srfile%%. %%srpath%% inserts the path to the file in which the search string was found and %%srfile%% inserts the filename of that file. %%srpath%% and %%srfile%% can be used in ordinary
search & replace operations, Regular Expression operations, Regular Expression counters, & Binary mode operations.
|
You can search for, or make replacements based on, Environment Variables via the Binary Mode dialog or a Regular Expression string. Searches may be case sensitive or not. The syntax is: %%envvar=variable name%% where variable name is the name of the environment variable to use. For example, to search for the environment variable temp, enter the string %%envvar=temp%% in the binary mode search block field or your regular expression. If the value of your temp environment variable is c:\windows\temp, search hits would occur wherever the string c:\windows\temp is found. If Case Sensitive is on, c:\windows\temp would be found but C:\WINDOWS\TEMP would not. To insert the value of the environment variable winbootdir in a replacement string, enter the string |
© 1995-2009 Funduc Software. All rights reserved. http://www.funduc.com.com/regexp.htm http://www.searchandreplace.com/regexp.htm Send comments to webmaster@searchandreplace.com |