Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Regular expression help Needed

by rockets12345 (Novice)
on May 06, 2005 at 03:11 UTC ( [id://454584]=perlquestion: print w/replies, xml ) Need Help??

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

Actually I have a some text data that looks something like below:
Starting the , text and there are more TESTBPR<b>PE12.3AZ234any +thing, BPR set ? & @ TRN $ ?of charactersCan be anything BPR* TRN# i +n here79something here11<b>TRN1 1415161718PE12.3AZST21 +st371718PE12.3AZST21stand so on and more text follows
How do I extract all the data between BPR and TRN Can someone help me in building the regular expression. Thanks

Replies are listed 'Best First'.
Re: Regular expression help Needed
by Forsaken (Friar) on May 06, 2005 at 08:51 UTC
    First of all, when asking a question and then later on changing it, it would be nice if you mentioned the question has been updated or modified. That way people that replied to the original question won't look as though they're talking out of their *insert favorite bodypart here*.

    As for the actual regex, you asked for all the data, so by that I assume you don't want to get rid of any html tags. I'll also assume you mean TRNsquare_thingy instead of the other way around...

    use strict; use warnings; my $blurb = 'Starting the , text and there are more TESTBPR<b>PE12. +3AZ234anything, BPR set ? & @ TRN $ ?of charactersCan be anythin +g BPR* TRN# in here79something here11<b>TRN1 1415161718P +E12.3AZST21st371718PE12.3AZST21stand so on and more text fol +lows'; #035 is the octal for that squarethingy you got there... $blurb =~ /\035BPR(.+)TRN\035/; print "result: $1\n";

    Remember rule one...

Re: Regular expression help Needed
by Roy Johnson (Monsignor) on May 06, 2005 at 03:43 UTC
    /([ -~]+)/g

    Caution: Contents may have been coded under pressure.
Re: Regular expression help Needed
by TedPride (Priest) on May 06, 2005 at 11:57 UTC
    This is a confusing question because there are several BPR's and TRN's, and you don't say whether you want the match to be greedy (everything from first BPR to last TRN) or non-greedy, or whether you want multiple matches returned.

    I'm guessing the latter, but my grasp of regex is still too weak to get it to return:

    <b>PE12.3AZ234anything, BPR set ? & @ *
    instead of:
    set ? & @ *
Re: Regular expression help Needed
by Grygonos (Chaplain) on May 06, 2005 at 13:15 UTC

    It seems like malformed data is breeding a malformed question here. If it is to be assumed that you truly want to find thing between BPR and TRN identifiers, then your desired output should be

    <b>PE12.3AZ234anything, BPR set ? & @
    and
    *

    which doesn't seem logical, which brings me to my original statement, malformed data breeds a malformed question. what kind of data is this and who's generating it? (If you're at liberty to say that is

    The regex however looks like the one above + minimal matchingm{BPR(.*)?TRN}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found