in reply to Re^2: how to remove a string from end of a line
in thread how to remove a string from end of a line
$str =~ s/(.*)\|.*/$1/;
Another way to look at this simple (i.e., up to Perl version 5.6, inclusive) match:
See YAPE::Regex::Explain. (Note: This module is good only for version 5.6 and earlier regexes.) See also perlre, perlretut, and perlrequick.c:\@Work\Perl\monks>perl -wMstrict -le "use YAPE::Regex::Explain; ;; print YAPE::Regex::Explain->new(qr/(.*)\|.*/)->explain; " The regular expression: (?-imsx:(.*)\|.*) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \| '|' ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
Update: The regex discussed above will remove the right-most pipe character, but your OPed examples suggest you want to keep this character. If this is so, I would recommend the substitution posted by johngg here.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to remove a string from end of a line
by ravi45722 (Pilgrim) on Oct 12, 2015 at 05:33 UTC | |
by AnomalousMonk (Archbishop) on Oct 12, 2015 at 05:48 UTC | |
by ravi45722 (Pilgrim) on Oct 12, 2015 at 06:08 UTC | |
by AnomalousMonk (Archbishop) on Oct 12, 2015 at 06:53 UTC | |
by ravi45722 (Pilgrim) on Oct 12, 2015 at 11:53 UTC | |
|