Technical References - [middle]

Extracts middle portion of the text between any two strings.

[middle startafter=x&endbefore=y]Any Text[/middle]

To display a subsection of some text, put the text inside a [middle] context.


[middle startafter=<body>&endbefore=</body>]
Hi There

The example above returns "Hi There," which is the sequence of letters between "<body>" and the last occurence of "</body>." Extracting sub-portions of text like this is useful when you need to remove the HTML header information from a file (or web page) containing HTML that you want to include inside the body of a web page.

The following parameters are required in the [middle] context:

startafterString of text characters to search for defining the beginning of the text to be returned. All preceding text (and the StartAfter text itself) will be ignored.
endbeforeString of text characters to search for defining the end of the text to be returned. If several occurence of the search string appear in the text, then the last one only will be relevant. All following text (and the EndBefore text itself) will be ignored.
startbefore(Available from v8.2) String of text characters to search for defining the beginning of the text to be returned. All preceding text will be ignored.
endafter(Available from v8.2) String of text characters to search for defining the end of the text to be returned. All following text will be ignored.

Example string: abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?


[middle startafter=f/&endbefore=/j][myVar][/middle]
[middle startafter=f/&endbefore=/][myVar][/middle]
[middle startafter=f/&endbefore=[url]&[/url]][myVar][/middle]
[middle startafter=f/&endbefore=&][myVar][/middle]
[middle startafter=f/&endbefore=/>][myVar][/middle]


From v8.2

[middle startafter=Subject: &endbefore=%0A&endcount=-1]
Message-Id: <>
From: Joshn Doe
Content-Type: text/plain; charset=US-ASCII; format=flowed
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v924)
Subject: [WebDNA] test message

Hello, this is a test

[WebDNA] test message

(WebDNA counts from the first line ending after the Subject:)

startcount and endcount can be positive or negative. A negative number counts from the opposite end it normally counts from. Positive numbers always count from the traditional direction that old WebDNA versions counted from. If you do not provide the startcount/endcount, they default to 1.

A startcount of -2 means "find the startafter/startbefore that is 2nd from the end of the string". Likewise, giving endcount of -2 means "find the endbefore/endafter that is 2nd from the beginning of the string".

When something isn't found, or if it isn't found enough times, then it ignores it. So for example, [middle startafter=q&startcount=10]xyz[/middle] will return xyz. This is the behavior of [middle] in previous versions, so it retains compatibility.


1.- [middle startbefore=f/&endafter=/j][myVar][/middle]
2.- [middle startafter=/&startcount=2][myVar][/middle]
3.- [middle endbefore=/&endcount=3][myVar][/middle]
4.- [middle endbefore=/&endcount=-3][myVar][/middle]
5.- [middle startbefore=/&endafter=/][myVar][/middle]
6.- [middle startafter=f/][myVar][/middle]
7.- [middle endbefore=/&startcount=5][myVar][/middle]
8.- [middle startbefore=f/][myVar][/middle]

1.- f/ghi/j
2.- ghi/jkl/&mno/pqr/>/stu/vwx/>yz?
3.- abc/def/ghi/jkl/&mno/pqr/>
4.- abc/def/ghi
5.- /def/ghi/jkl/&mno/pqr/>/stu/vwx/
6.- ghi/jkl/&mno/pqr/>/stu/vwx/>yz?
7.- abc/def/ghi/jkl/&mno/pqr/>/stu/vwx
8.- f/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?

For #7, the "startcount" is ignored because startcount is only used with "startbefore" and "startafter". Since no startbefore or startafter is provided, there is nothing to use startcount with. The default "endcount" of 1 is used instead since "endbefore" is provided.


Top Articles:

Tips and Tricks

A list of user-submitted tips ...


A compilation of some user's questions...

WebDNA reference

A list of all WebDNA instructions...

WebDNA Libraries

A list of available libraries for WebDNA...

AWS Raw WebDNA LAMP-Plus WebServer

Amazon Web Services (AWS) README for Machine Image ID...

Download WebDNA Applications

WebDNA applications...

Related Readings:


Using [password] and [username] is an easy was to show the browser login dialog box...


Hides text...


Creates a new thread to execute WebDNA simultaneously with the current template...


[thisurl] displays the URL of the current page...


[showif Comparison]Show This HTML[/showif]...


Changes text from URL-compatible characters to plain text...