Microsoft
Software
Hardware
Network
Question : Ruby RegEx search and replace
This should be simple:
text = 'adam|paul|mike'
I want to replace that with ->
adam
paul
m
ike
So each name seperated by a | OR a name at the end of the string should be enclosed in
tags. Here's what I have so far:
text.gsub(/[a-z]*[|\Z]/, '
\0
')
But this leaves off the last name. I'd also like to replace [a-z]* with just .* - (which for some reason is way off)
As a bonus, is there a way to also get the values inside the
tags to drop the | - but that can always easily be done in a second step
Thanks!
Answer : Ruby RegEx search and replace
use split to break the string in an array, change the diffrent items in place using collect and join the remainder array
text = 'adam|paul|mike'
arr = text.split('|')
arr.collect!{|a| '
' + a + '
' }
puts arr.join
easy, no?
Random Solutions
Windows Installer Transform cannot be found
A system driver MUP.SYS hangs too much the computer
How to decrypt the encrypted password ? Any good algorithm or PL/SQL Code??
COFF header and timestamp
Which version of WDS am I running?
Basic Exchange 2007 Configuration Question
Can Javascript in Acrobat get the next month and enter into multiple form fields?
How to delete email messages within a date range. say 6/01/08 to 6/15/08. Blackberry on BES server.
Text Box with Cell Reference *and* other text?
Error 1923. Service 'SQL Server ()' () could not be installed.