我有一个Ruby字符串,看起来像:
"AUTO TESTnJANE DOE-RIGHTn12097105nJOE BINn1216515nREGRESSION SUE TESTn10023436"
注意AUTO TEST
后面没有数字。然后我想把它变成这样:
"AUTO TESTnJANE DOE-RIGHT12097105nJOE BIN1216515nREGRESSION SUE TEST10023436"
移除n
,只有它站在数字的正前方。结果可以是数组,也可以是另一个字符串。
您可以尝试将n(?=d)
替换为空字符串:
input = "AUTO TESTnJANE DOE-RIGHTn12097105nJOE BINn1216515nREGRESSION SUE TESTn10023436"
output = input.gsub(/n(?=d)/, '')
puts output
这个打印:
AUTO TEST
JANE DOE-RIGHT12097105
JOE BIN1216515
REGRESSION SUE TEST10023436