Need help with "get MatchText" to get a value of a

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

Need help with "get MatchText" to get a value of a

Post by alex298 » Mon May 28, 2007 10:02 am

Hello,

I am very poor at Regular Expression. I tried for a few hours and still could not get the answer. My problem is:

The following is a single line:

<td bgcolor="#CCCCCC" align="center" width="53"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">10.94</font></td>

I wish to get the 10.94 value by using the get MatchText(myVar, ".......", ) but no luck. Could someone please help me to get the answer.

Thanks and best regards
Alex
Nice to meet all of you.

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Re: Need help with "get MatchText" to get a value

Post by Mark Smith » Mon May 28, 2007 2:25 pm

Alex, I can't help you with regular expressions, but bear in mind that Revolutions own chunk expressions can be very powerful.

In the case you've given, you could do this:

assume the line is in a variable <tLine>

Code: Select all

function extractValue tLine
   replace ">" with ">" & cr in tLine
   replace "<" with cr in tLine
   filter tLine without empty
   filter tLine without "*>"
   return tLine
end extractValue
This is just off the top of my head, so is not necessarily the best possible way, but will work for the example given.

Best,

Mark

xApple
Posts: 113
Joined: Wed Nov 29, 2006 10:21 pm

Post by xApple » Mon May 28, 2007 9:08 pm

I see two other ways of achieving the same result, that might be better.
First, as this happens to be HTML, you could use a trick by setting the HTMLText of a field like this:

Code: Select all

function extractValue tLine 
   set the htmltext of field "tempField" to tLine
   return field "tempField" 
end extractValue 
And here is for the regular expression you were looking for... looks like a sort of big smiley ^^ They can be hard to learn at first, but it's really all hardcore logic.

Code: Select all

function extractValue tLine 
   matchText(tLine,">([^<>]+)<",tempVar)
   return tempVar
end extractValue 

alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

Post by alex298 » Tue May 29, 2007 3:41 am

Hi,

Thanks for your great help. All methods are really very interesting and I learn a lot.

Actually I am always using itemDel, a easier method and can achieve expected result in many cases. However this is quite "boring" and I really wish to learn other ways. For example:

put field "htmlCode" into tData
set the itemDel to ">"
put item 3 of tData into tData
set the itemDel to "<"
put item 1 of tData into field "Result"

Thanks and best regards
Alex
Nice to meet all of you.

Post Reply