RegExp Type

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

RegExp Type

Mark Palmer
Hi,

I'm trying to use the RegExp type to programatically increase some  
prices in a file.

Here is an example of the data:

@Odd:<@Picture Box><@$p> 3G <@Red Text>SM23EPC £51.00<@$p> <@Blue  
Text>SM23ESC £51.00<@$p> <@Green Text>SM23ESS £51.00<@$p>
@description:Double Plate With Four Gang Modular & Nil Blank
@Odd:<@Picture Box><@$p> 4G <@Red Text>SM24EPC £64.00<@$p> <@Blue  
Text>SM24ESC £64.00<@$p> <@Green Text>SM24ESS £64.00<@$p>');

I can hit the prices with this regexp

$myRegExp = RegExp(-Find='(?s)£(\\d{1,3}\\.\\d{2})<@\\$p>', -Input=
$myString, -IgnoreCase);


While($myRegExp->Find);
        Var('myMatch' = $myRegExp->MatchString);
        Loop_Count': 'Encode_HTML($myMatch)'<br />';
/While;

But my match string includes the £ and the <@\\$p> rather than the  
output of the () grouping.

It seems from the Language guide on page 348 I need to use RegExp-
 >Split, but I can't for the life of me get the syntax quite right  
and make it work.

Any ideas?

Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




============================================
Attend the Lasso Summit
March 2-4, 2007 in Fort Lauderdale, FL
http://www.LassoSummit.com/
============================================

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: RegExp Type

James Harvard
Never got into the regexp type so not sure about that, but there is a pure regex solution using positional assertions? These match but without being included in the final match string.

(?<=£) means "is preceeded by £"
(?=<@\$p>) means "is followed by <@$p>"

So ...

-find='(?s)(?<=£)\\d{1,3}\\.\\d{2}(?=<@\\$p>)'

HTH,
James

>I can hit the prices with this regexp
>
>$myRegExp = RegExp(-Find='(?s)£(\\d{1,3}\\.\\d{2})<@\\$p>', -Input=$myString, -IgnoreCase);
>
>While($myRegExp->Find);
> Var('myMatch' = $myRegExp->MatchString);
> Loop_Count': 'Encode_HTML($myMatch)'<br />';
>/While;
>
>But my match string includes the £ and the <@\\$p> rather than the output of the () grouping.

============================================
Attend the Lasso Summit
March 2-4, 2007 in Fort Lauderdale, FL
http://www.LassoSummit.com/
============================================

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: RegExp Type

Mark Palmer
I might be being a little dumb here but are you saying that I could  
then add 7.5% to all of the decimals purely with RegExp in BBEdit for  
example?


On 26 Feb 2007, at 17:13, James Harvard wrote:

> Never got into the regexp type so not sure about that, but there is  
> a pure regex solution using positional assertions? These match but  
> without being included in the final match string.
>
> (?<=£) means "is preceeded by £"
> (?=<@\$p>) means "is followed by <@$p>"
>
> So ...
>
> -find='(?s)(?<=£)\\d{1,3}\\.\\d{2}(?=<@\\$p>)'
>
> HTH,
> James
>
>> I can hit the prices with this regexp
>>
>> $myRegExp = RegExp(-Find='(?s)£(\\d{1,3}\\.\\d{2})<@\\$p>', -Input=
>> $myString, -IgnoreCase);
>>
>> While($myRegExp->Find);
>> Var('myMatch' = $myRegExp->MatchString);
>> Loop_Count': 'Encode_HTML($myMatch)'<br />';
>> /While;
>>
>> But my match string includes the £ and the <@\\$p> rather than the  
>> output of the () grouping.
>
> ============================================
> Attend the Lasso Summit
> March 2-4, 2007 in Fort Lauderdale, FL
> http://www.LassoSummit.com/
> ============================================
>
> ------------------------------
> Lasso Support: http://support.omnipilot.com/
> Search the list archives: http://www.listsearch.com/lassotalk.lasso
> Manage your list subscription:
> http://www.listsearch.com/lassotalk.lasso?manage






Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




============================================
Attend the Lasso Summit
March 2-4, 2007 in Fort Lauderdale, FL
http://www.LassoSummit.com/
============================================

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: RegExp Type

Fletcher Sandbeck
In reply to this post by Mark Palmer
> I'm trying to use the RegExp type to programatically increase some
> prices in a file.
>
> Here is an example of the data:
>
> @Odd:<@Picture Box><@$p>  3G  <@Red Text>SM23EPC  £51.00<@$p> <@Blue  
> Text>SM23ESC  £51.00<@$p> <@Green Text>SM23ESS    £51.00<@$p>
> @description:Double Plate With Four Gang Modular & Nil Blank                          
> @Odd:<@Picture Box><@$p>  4G  <@Red Text>SM24EPC  £64.00<@$p> <@Blue  
> Text>SM24ESC  £64.00<@$p> <@Green Text>SM24ESS    £64.00<@$p>');
>
> I can hit the prices with this regexp
>
> $myRegExp = RegExp(-Find='(?s)£(\\d{1,3}\\.\\d{2})<@\\$p>', -Input=
> $myString, -IgnoreCase);
>
>
> While($myRegExp->Find);
>   Var('myMatch' = $myRegExp->MatchString);
>   Loop_Count': 'Encode_HTML($myMatch)'<br />';
> /While;
>
> But my match string includes the £ and the <@\\$p> rather than the  
> output of the () grouping.
>
> It seems from the Language guide on page 348 I need to use RegExp-
>  >Split, but I can't for the life of me get the syntax quite right  
> and make it work.

You have to specify which sub-pattern you want to retrieve using
->MatchString.

    Var('myMatch' = $myRegExp->MatchString(1));

[fletcher]
--
Fletcher Sandbeck                         [hidden email]
Director of Product Development       http://www.lassostudio.com
OmniPilot Software, Inc.                http://www.omnipilot.com

============================================
Attend the Lasso Summit
March 2-4, 2007 in Fort Lauderdale, FL
http://www.LassoSummit.com/
============================================

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: RegExp Type

Mark Palmer

On 26 Feb 2007, at 17:20, Fletcher Sandbeck wrote:

>> I'm trying to use the RegExp type to programatically increase some
>> prices in a file.
>>
>> Here is an example of the data:
>>
>> @Odd:<@Picture Box><@$p>  3G  <@Red Text>SM23EPC  £51.00<@$p> <@Blue
>> Text>SM23ESC  £51.00<@$p> <@Green Text>SM23ESS    £51.00<@$p>
>> @description:Double Plate With Four Gang Modular & Nil Blank
>> @Odd:<@Picture Box><@$p>  4G  <@Red Text>SM24EPC  £64.00<@$p> <@Blue
>> Text>SM24ESC  £64.00<@$p> <@Green Text>SM24ESS    £64.00<@$p>');
>>
>> I can hit the prices with this regexp
>>
>> $myRegExp = RegExp(-Find='(?s)£(\\d{1,3}\\.\\d{2})<@\\$p>', -Input=
>> $myString, -IgnoreCase);
>>
>>
>> While($myRegExp->Find);
>>   Var('myMatch' = $myRegExp->MatchString);
>>   Loop_Count': 'Encode_HTML($myMatch)'<br />';
>> /While;
>>
>> But my match string includes the £ and the <@\\$p> rather than the
>> output of the () grouping.
>>
>> It seems from the Language guide on page 348 I need to use RegExp-
>>> Split, but I can't for the life of me get the syntax quite right
>> and make it work.
>
> You have to specify which sub-pattern you want to retrieve using
> ->MatchString.
>
>     Var('myMatch' = $myRegExp->MatchString(1));
>
> [fletcher]
> --

OMG - it was that simple.

Thanks Fletcher.

Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




============================================
Attend the Lasso Summit
March 2-4, 2007 in Fort Lauderdale, FL
http://www.LassoSummit.com/
============================================

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: RegExp Type

James Harvard
In reply to this post by Mark Palmer
No, but you can match just the numbers without including the £ and <@$p> delimiters.

Using your sample data:
string_findregexp: $sample_data, -find='(?s)(?<=£)\\d{1,3}\\.\\d{2}(?=<@\\$p>)' ;
// returns "array: (51.00), (51.00), (51.00), (64.00), (64.00), (64.00)"

James

>I might be being a little dumb here but are you saying that I could then add 7.5% to all of the decimals purely with RegExp in BBEdit for example?
>
>On 26 Feb 2007, at 17:13, James Harvard wrote:
>>Never got into the regexp type so not sure about that, but there is a pure regex solution using positional assertions? These match but without being included in the final match string.
>>
>>(?<=£) means "is preceeded by £"
>>(?=<@\$p>) means "is followed by <@$p>"
>>
>>So ...
>>
>>-find='(?s)(?<=£)\\d{1,3}\\.\\d{2}(?=<@\\$p>)'

============================================
Attend the Lasso Summit
March 2-4, 2007 in Fort Lauderdale, FL
http://www.LassoSummit.com/
============================================

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage