in reply to Regex with condition
Further to your updated OP:
Why are you substituting newlines with spaces? The first approach given in my reply above, the one based on slurping the entire file (as you seem now to be doing), depends on having all newlines preserved. If your final text needs to be without newlines, I think the best time to get rid of them would be after all changes to the text have been made because those changes are all defined (or were defined in the original Original Post) in terms "lines", i.e., with reference to newlines.
However, also note that if the "random amount of other text" preceding the 'b' in a trigger line may contain any whitespace, then the
my $pre = qr{ \S+ \s }xms;
regex will have to be changed accordingly.
Update: When updating a post, please do not destroy original content; instead, indicate defunct content as such (e.g., with <strike> ... </STRIKE> tags or in a brief note). Likewise, indicate added content in some way. The Golden Rule: Thou shalt not destroy the context of previous replies. Please see How do I change/delete my post?.
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex with condition
by OldChamp (Acolyte) on Nov 19, 2015 at 16:29 UTC | |
by AnomalousMonk (Archbishop) on Nov 19, 2015 at 20:39 UTC | |
by OldChamp (Acolyte) on Nov 19, 2015 at 23:26 UTC | |
by AnomalousMonk (Archbishop) on Nov 20, 2015 at 17:03 UTC |