Grep & Regex

[grep] context

This popular UNIX utility has been adapted to WebDNA. [grep] replaces text based on a regular expression.
[grep search=regexp&replace=regexp] Any Text [/grep]

Parameters

ParameterDescription
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

(Optional) T/F ignores case sensitivity while performing the grep function
Example WebDNA code:
[grep search=([0-9]*-[0-9]*)&replace=<strong>\1</strong>]
  Hi, my phone number is 555-1234, and I'd like you to call me
[/grep]
Results:
Hi, my phone number is 555-1234, and I'd like you to call me

Using 'ignorecase' parameter in [grep] context. Search for 'usa' and replace with 'USA'

Example WebDNA code:
[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]
Results:
I was born in the USA
I was born in the USA
I was born in the USA

Removing html tags from text

Example WebDNA code:
[grep search=(<[a-z]*>[^<>]*<\/[a-z]*>|<[a-z]*>)&replace=]
  <script>remove the code that's here 1</script> but not here 1 <br> <hr>
  <script>remove the code that's here 2</script> but not here 2 <br> <hr>
  <script>remove the code that's here 3</script> but not here 3 <br> <hr>
[/grep]
Results:
but not here 1 but not here 2 but not here 3

[regex] WebDNA v8.1+ context

[regex] is a full implementation of [grep], starting from version 8.1 of WebDNA. The older implementation of [grep] remains for backward compatibility for its simple search and replace capabilities, however, [regex] is a better choice.

Syntax is the same as for [grep], except that it does not have the limitations of WebDNA's implementation of [grep]

Some specific operators used by [regex] will be interpreted by WebDNA, like "%2B" or "%26" for instance. In this case, it is safer to [url][/url] the operator like in the following

Example WebDNA code:
[text]value=\b0%2B[/text]
[regex search=[value]&replace=]080.010.001.305[/regex]
or
[text]value=\b0+[/text]
[regex search=[url][value][/url]&replace=]080.010.001.305[/regex]
Results: both will show 80.10.1.305