
hydpm
User
Sep 5, 2008, 12:46 PM
Post #1 of 4
(1747 views)
|
|
Typical Search and repalce with Regular expression
|
Can't Post
|
|
Hi, I wanted to do the following. $Input may have one of the following values: 10 m 1 h 2 h 3 d 4 w What i need to do is : I should grab the one of the above values from $input then search and repalce like below: 10 min/s 1 hour 2 hours 3 day/s 4 weeks Where i blocked is : (\S+) mathces other than spaces i.e m,h,h/s,d,w. The conversion will be if "1 h" found then it should be converted to "1 hour" . If "2 h" then it should be converted to "2 hours". If it is "10 m" then to "10 min/s" etc. How do i make the expression conditionally here. Need help on that? The more tricky on hour part. $input=~s/(\d+)(\s+)(\S+)/$1$2(Need Help here)/ Thanks, Raj
|