On 10/28/07, Junkone <junkone1 / gmail.com> wrote:
> Hello
> I have a date like 20070801 in a string. how do i change it to
> 2007/08/01 using regex
> thanks

irb(main):008:0> '20070801'.sub( /(\d{4})(\d{2})(\d{2})/ ) { [ $1, $2,
$3 ].join( '/' ) }
=> "2007/08/01"

OR:

irb(main):010:0> '20070801'.sub( /(\d{4})(\d{2})(\d{2})/, '\1/\2/\3')
=> "2007/08/01"

-Tom