查找以下字符串的正则表达式

时间:2014-12-11 04:43:32

标签: regex ruby-on-rails-4

我有字符串,该字符串有四种格式:

str = "A. B.C. D, WOW, 'H' BENCH"

str1 = "ABCD WOW BENCH \"k\""

str2 = "A.B.C.D,. WOW 'K' BENCH"

str3 = "ABCD, WOW 'K' BENCH"

字符串将以任何一种格式出现,所以我想要正则表达式,它将分别给出以下结果:

str = "ABCD WOW H BENCH"

str1 = "ABCD WOW BENCH K"

str2 = "ABCD WOW K BENCH"

str3 = "ABCD WOW K BENCH"

1 个答案:

答案 0 :(得分:1)

使用此正则表达式,然后将匹配替换为空字符串:

(?<=\.) (?=[A-Z]\b)|[.,'"]

这是demonstration