Tips_todo   >   Misc   >   Find And Replace
$findandreplace(cFind,cReplace[,bIgnoreCase=kTrue,bWholeWord=kFalse,bRegExp=kFalse])
You can use the $findandreplace method on a class.
Note the 4th optional parameter, bRegExp. If you send bRegExp as kTrue Omnis will allow you to use the power of regular expressions (regexps) in your find and replace notation! This makes it possible to do some pretty crazy find and replace code and save yourself a ton of work and time if you need to do some extensive changes to existing code. (Always work with a test copy of your library!)
How about adding regexps intelligence to the correspondence module of an application you have written? With a little creative code you can use OMST's regexps engine for this feature. Here's how.
Square brackets [] give you extra flexibility in your searches.
gr[ae]y will find gray, and greyli[ce]en[sc]e will find license, licence, lisence, licence
555-[0-9][0-9][0-9][0-9] will find phone numbers beginning with 555-
[Tt][Cc][Pp] will find TCP, tcp, TcP
You can use more than one range.
[0-5a-fA-F] will find any number between 0 and 5 or a letter A to F or a to f
The ^ character means begins with.
Note: If you are searching comment lines remember they begin with the ; character followed by 2 spaces.
^;..555- will find all the comment lines that begin with 555 (The dot . is a single character wildcard)
The $ character means ends with.
$-1212 will find all the lines that end with -1212For more information on regexps check out http://www.regular-expressions.info
The Find and Replace dialog window has a check box for Regular Expressions.
Regular expression is a term from the Unix world and is often shortened to regexps.
If you are not experienced with using the regexps (like me) the following tips and examples will be helpful.
Most of us are familiar with using the * and ? wildcard characters when listing files at the DOS prompt or Unix command line.
With regular expresssions the meaning of the * and ? are different and the dot . is added to the mix.
The * character means any number of characters including none of the metacharacter that precedes the * character.
t* will find t, tt, ttt
t* will not find ta, tcp, tub
The . (single dot) character means any single character
ta. will find tab, tan, tab
ta. will not find ta
Combining the . and * together matches any number or any character.
t.* will find t, tt, ttt, ta, tab, tan, tap
If we want to find all the lines of code which use a $search within a $search the following regexps would do the trick:
search.*search
The $ character is a special character used by regexps so you need to escape the $ with a \ backslash character if you want to include the actual $ character in your regexps
\$search.*\$search
The | vertical bar character means or
tt|tan will find tt, ttt, tan, tankThis is only the tip of the iceburg of what you can do with regexps.