2011-03-22 78 views

回答

1

下面介紹如何使用Ruby做(測試):

s = '1234123412341234' 
s.sub!(/(\d{4})(\d{4})(\d{4})(\d{4})/, '\1 \2 \3 \4') 
print s # => "1234 1234 1234 1234" 

我沒有對象 - 花花公子,但RegexKit或RegexKit精簡版,該代碼應爲(未經測試)類似:

[string stringByMatching:@"(\d{4})(\d{4})(\d{4})(\d{4})" replace:1 withString:@"$1 $2 $3 $4"] 

一些更多的閱讀: