Inserting text before and after regex

philsivyer
philsivyer used Ask the Experts™
on
Hello
I want to inset text before and after a date - example.

str5="Royal coronation year and dob is 1952/12/14 - great year. Another
good year was 1966/01/01"
puts str5.match(/\b(\d\d\d\d)\/(\d\d)\/(\d\d)/)

So, what I would like is to put say "YEAR" before and "END" after each date found
in the given format. So, the final result would be...

"Royal coronation year and dob is YEAR 1952/12/14 END- great year. Another
good year was YEAR 1966/01/01 END"
Regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
Commented:
str5="Royal coronation year and dob is 1952/12/14 - great year. Another
good year was 1966/01/01"
puts str5.gsub(/\b(\d\d\d\d\/\d\d\/\d\d)/, 'YEAR \1 END')

Author

Commented:
Thanks
Welcome back - where have you been?
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
busy
and spending the little time I had left for Experts Exchange in teh XSLT zone
I am happy that you missed me :-)

Author

Commented:
Now I know where you are - thanks!
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
welcome

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial