Extracts middle portion of the text between any two strings.
numero = 270[middle startafter=<body>&endbefore=</body>]<html><head></head><body>Hi There</body></html>[/middle]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:
Parameter | Description |
---|---|
startafter | String 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. |
endbefore | String 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. |
[text]myVar=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text][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]Results:ghighi/jkl/&mno/pqr/>/stu/vwxghi/jkl/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?ghi/jkl/&mno/pqr/>/stu/vwxFrom v8.2
[middle startafter=Subject: &endbefore=%0A&endcount=-1]Message-Id: <1874F5DF-301E-4560-8C37-63BD903EA7E4@zarcrom.com>From: Joshn DoeResult:[WebDNA] test message(WebDNA counts from the first line ending after the Subject:)To: talk@webdna.usContent-Type: text/plain; charset=US-ASCII; format=flowedContent-Transfer-Encoding: 7bitMime-Version: 1.0 (Apple Message framework v924)Subject: [WebDNA] test messageHello, this is a test[/middle]
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.
[text]myVar=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text]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]Results:1.- f/ghi/j2.- ghi/jkl/&mno/pqr/>/stu/vwx/>yz?3.- abc/def/ghi/jkl/&mno/pqr/>4.- abc/def/ghi5.- /def/ghi/jkl/&mno/pqr/>/stu/vwx/6.- ghi/jkl/&mno/pqr/>/stu/vwx/>yz?7.- abc/def/ghi/jkl/&mno/pqr/>/stu/vwx8.- 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.
[middle startafter=x&endbefore=y]Any Text[/middle][middle startafter=<body>&endbefore=</body>]
<html>
<head>
</head>
<body>
Hi There
</body>
</html>
[/middle]
Parameter | Description |
---|---|
startafter | String 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. |
endbefore | String 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. |
[text]myVar=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text]
[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]
[middle startafter=Subject: &endbefore=%0A&endcount=-1]
Message-Id: <1874F5DF-301E-4560-8C37-63BD903EA7E4@zarcrom.com>
From: Joshn Doe
To: talk@webdna.us
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
[/middle]
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.
[text]myVar=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text]
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]
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.
DOWNLOAD WEBDNA NOW!
A list of available libraries for WebDNA...
WebDNA reference...
AWS Raw WebDNA LAMP-Plus WebServerAmazon Web Services (AWS) README for Machine Image ID...
WebDNA ModulesA list of the currently available modules...
F.A.QA compilation of some user's questions...
Tips and TricksA list of user-submitted tips ...
Extracts a portion of the text (also known as substring or Mid$)...
[createfolder]Create an empty folder on your webspace...
[append][append db=base...
[fileinfo]Displays information about a particular file or folder...
[listdatabases]Lists all the currently-open databases...
[text]Text variables are fundamental building blocks of the WebDNA language...