Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

get the string upto word containing tag block

by shan_emails (Beadle)
on Aug 17, 2010 at 06:50 UTC ( [id://855409]=perlquestion: print w/replies, xml ) Need Help??

shan_emails has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

Is there any option to get the pattern in $str variable. ie., upto 1st match of word containing "<w:t>" tag block.

for example
$str = '<w:pict>4</w:pict> </w:r></w:p><w:tbl><w:tblPr> <w:t> </w:t> <w:t>Figure 2.</w:t> <w:t>Figure 3.</w:t> <w:pict>5</w:pict>';


then the output become $output = '<w:pict>4</w:pict> </w:r></w:p><w:tbl><w:tblPr> <w:t> </w:t> <w:t>Figure 2.</w:t>';
if $str = '<w:pict>4</w:pict> </w:r></w:p><w:tbl><w:tblPr> <w:t>Figure 2.</w:t> <w:t>Figure 3.</w:t> <w:pict>5</w:pict>'; Then output becomes $str = '<w:pict>4</w:pict> </w:r></w:p><w:tbl><w:tblPr> <w:t>Figure 2.</w:t>';


Thanks,
Shanmugam A.

Replies are listed 'Best First'.
Re: get the string upto word containing tag block
by suhailck (Friar) on Aug 17, 2010 at 07:01 UTC
    Is this what you looking for, my ($output)=$str=~m{(.*?</w:t>)}ms;
Re: get the string upto word containing tag block
by prasadbabu (Prior) on Aug 17, 2010 at 07:21 UTC

    Hi Shanmugam,

    If I understood your quesion well, this dirty code will give your output. BUT TIMTOWTDI.

    $str = '<w:pict>4</w:pict> </w:r></w:p><w:tbl><w:tblPr> <w:t> </w:t> <w:t>Figure 2.</w:t> <w:t>Figure 3.</w:t> <w:pict>5</w:pict>'; $str = qr{$str}; $str =~ m|^((((?![^\s]+<\/w:t>).)+).+?(<\/w:t>))|s; $new_str = $1; $new_str =~ s|(<w:t>\w(((?!</w:t>).)+)</w:t>).+$|$1|s; print $new_str; output: ======= <w:pict>4</w:pict> </w:r></w:p><w:tbl><w:tblPr> <w:t> </w:t> <w:t>Figure 2.</w:t>

    Prasad

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://855409]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-16 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found