Grep Context

[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

User Contributed Notes
GrepContext  

Bill DeVaul  
05/23/2003 at 08:19:12
Can someone clean up the page so that the results follow the sample code more closely?

Talklist  
11/14/2003 at 13:48:00
Pass a Form

Example of passing details from a <textarea> to another page without losing the line breaks.

[grep search=%0D&replace=<br>]

Copyright © 2008 WebDNA Software Corporation, Inc.