For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > lazy capture don't work









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author lazy capture don't work
Meir Yanovich

2006-09-01, 7:57 am



=20
=20
hello all=20
im trying to capture only the first brackets but no matter what i do i
keep capturing from the first brackets to the last one , here what i
have :
<% if (!Env.strLen(oidInvoice)); szDocumentTitle =3D
Env.formatS("S",Env.getMsg("BP_INVOICE_ENUMERATION_CREATE_TITLE")) %>

and the regexp i have is :=20

<%\s*(if\s*\(.+?\))\s*%>

i like to capture only : if (!Env.strLen(oidInvoiceEnum))=20
with no luck what im doing wrong?
Manish

2006-09-01, 6:57 pm

try

<.*(if\s*\(.*\)\);).*>

Manish

Meir Yanovich wrote:
> hello all
> im trying to capture only the first brackets but no matter what i do i
> keep capturing from the first brackets to the last one , here what i
> have :
> <% if (!Env.strLen(oidInvoice)); szDocumentTitle =
> Env.formatS("S",Env.getMsg("BP_INVOICE_ENUMERATION_CREATE_TITLE")) %>
>
> and the regexp i have is :
>
> <%\s*(if\s*\(.+?\))\s*%>
>
> i like to capture only : if (!Env.strLen(oidInvoiceEnum))
> with no luck what im doing wrong?


Paul Lalli

2006-09-01, 6:57 pm

Meir Yanovich wrote:
> im trying to capture only the first brackets


You need to define what you mean by "bracket", because there are none
in the code below.

"<" less than
">" greater than
"[]" square brackets
"{}" curly braces
"()" parentheses.

> but no matter what i do i
> keep capturing from the first brackets to the last one


How about you show us some of the attempts?

> , here what i have :
> <% if (!Env.strLen(oidInvoice)); szDocumentTitle =
> Env.formatS("S",Env.getMsg("BP_INVOICE_ENUMERATION_CREATE_TITLE")) %>
>
> and the regexp i have is :
>
> <%\s*(if\s*\(.+?\))\s*%>


This says to match:
less than, percent, 0 or more whitespace, [start capture], if, 0 or
more whitespace, left parenthesis, at least one of anything
(minimally), right parenthesis, [end capture], 0 or more whitespace,
percent, greater than.

There's only one "percent, greater than" in your string. So how are
you expecting the "anything" portion to match anything less?

>
> i like to capture only : if (!Env.strLen(oidInvoiceEnum))
> with no luck what im doing wrong?


Telling Perl you want to capture a lot more than you're telling us you
want to capture. You need to better explain to us what defines how
much you want to capture. What, in words, is the pattern? Is it up to
the first semicolon? Up to the second right parenthesis? Up to the
first space character after the first parenthesis?

Without this information, it's impossible to give you a pattern that
will work on any string. The only thing we *can* give you that will
meet the requirements you've specified is:
/(\Qif (!Env.strLen(oidInvoiceEnum))\E)/
which I'm guessing is not what you want.

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com