[Grep search=regexp&replace=regexp]Any Text[/Grep]

Replaces text based on a regular expression. This popular UNIX utility has been adapted to WebDNA.

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[Grep search=([0-9]*-[0-9]*)&replace=<b>\1</b>]Hi, my phone number is 555-1234, and I'd like you to call me[/Grep]

In the example above, the displayed text will be

Hi, my phone number is <b>555-1234</b>, and I'd like you to call me
 Parameter  Description
search
(Required) Regular expression that defines what text to search for in the body of the context
replace
(Required) Regular expression that defines how to output the resulting text

IgnoreCase

New for 5.0

(Optional) ignores case sensitivity while performing the grep function

There is a new 'IgnoreCase' parameter for the [GREP] context. Here is an example:

Search for 'usa' and replace with 'USA'


[grep search=usa&replace=USA&ignorecase=T]
I was born in the usA

I was born in the uSa

I was born in the Usa

[/grep]


Other examples...

 

[grep search=[0-9]*(ScOtT)[0-9]*&replace=___\1___&IgnoreCase=T]123scott321
[/grep]
[grep search=staging&replace=development&IgnoreCase=T]/Staging/myfile[/grep]

Results:


I was born in the USA
I was born in the USA
I was born in the USA

Other examples...


___scott___
/development/myfile