Regex: match this string

I can not figure it out:

22.584\r\n\t\t\tl-6.579-22 

I want to match "\r\n\t\t\t" and replace it with a single space " " . The problem is the number of "\t" , "\r" and "\n" , as well as surrounding characters.

Help!

+3
ruby regex
source share
6 answers

s/\s+/ /g div>

 s/(?:\\[rnt])+/ /g 
+4
source share

In PHP:

 preg_replace("/(?:\\\[trn])+/", " ", $str); 
0
source share
 sed 's/\\[rnt]/ /g;s/ */ /g' 
0
source share
 '22.584\r\n\t\t\tl-6.579-22'.gsub(/(\\[rnt])+/, ' ') 
0
source share
 #!/usr/bin/ruby1.8 s = "22.584\r\n\t\t\tl-6.579-22" ps # => "22.584\r\n\t\t\tl-6.579-22" p s.gsub(/[\r\n\t]+/, ' ') # => "22.584 l-6.579-22" 
0
source share

I would consider CR-NL as one atom:

 str.gsub!(/(?:\r\n)+\t+/, ' ') 
0
source share

All Articles