
BillKSmith
Veteran
Sep 17, 2012, 8:14 PM
Post #3 of 4
(11943 views)
|
Re: [Laurent_R] HELP!!Regex to match boundary from a range and substitute characters
[In reply to]
|
Can't Post
|
|
Replace a leading 'L' with a 'Z' only if it is followed by any character in the range [a-i]. (Refer to documentation for zero-width positive lookahead assertion.) Print successful substitutions.
use strict; use warnings; my @phone = <DATA>; print grep {s/^L(?=[a-i])/Z/} @phone; __DATA__ Joshua Smith John Jenkins Larry Roberts Bob Jones Linda Green Tim Anderson Adam Jackso Consider using a one-liner.
perl -pe"$_=q() unless s/^L(?=[a-i])/Z/" names.dat Note: Quoting is for windows. You may have to replace double quotes with single quotes. Good Luck, Bill
(This post was edited by BillKSmith on Sep 17, 2012, 8:33 PM)
|