Page 1 of 1

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

Posted: Mon May 28, 2007 10:02 am
by alex298
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

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

Posted: Mon May 28, 2007 2:25 pm
by Mark Smith
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

Posted: Mon May 28, 2007 9:08 pm
by xApple
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 

Posted: Tue May 29, 2007 3:41 am
by alex298
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