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

Aero Research Labs.###FundingOrg[###Date______[ Dec 1963

Given the record above I'm looking for a regex that will delete '###FundingOrg['
s/###FundingOrg\[//;
But I might have a case were
Aero Research Labs.###FundingOrg[ BBC###Date______[ Dec
There could be any resonable text or nothing after the '[' in the FundingOrg field. So my question is what is the trick to making a regex so it will delete that field. Is these a way to anchor to the 1st '###' after '###FundingOrg[' and say stop the regex when you get to the 1st '####'?
Thanks
edited by demerphq: changed unclosed to square bracket to entities.

Replies are listed 'Best First'.
Re: deleting a field in a flat-file
by davidj (Priest) on Jun 24, 2004 at 01:41 UTC
    Given:
    Aero Research Labs.###FundingOrg[###Date______[ Dec 1963 Aero Research Labs.###FundingOrg[ BBC###Date______[ Dec
    if you want to delete everything starting with "###FundingOrg[" and ending with everything up to but not including the following "###", the following will do the trick:

    while(<DATA>) { chomp($_); $_ =~ s/###FundingOrg\[.*?(?=###)//; print $_ . "\n"; } __DATA__ Aero Research Labs.###FundingOrg[###Date______[ Dec 1963 Aero Research Labs.###FundingOrg[ BBC###Date______[ Dec
    output:
    Aero Research Labs.###Date______[ Dec 1963 Aero Research Labs.###Date______[ Dec
    hope this helps,
    davidj
Re: deleting a field in a flat-file
by Fletch (Bishop) on Jun 24, 2004 at 01:32 UTC
    print join( "###", ( split( /###/, $_, 3 ) )[0,2] ), "\n";
Re: deleting a field in a flat-file
by Anonymous Monk on Jun 24, 2004 at 01:37 UTC
    I may be less inept that I think:
    s/FundingOrg\[.*###//;
    
    I know this is newbie stuff here - it'll do it. Right? I will test it.