Ruby 关于 Ruby 的正则问题

lgor · June 14, 2018 · Last by lgor replied at June 14, 2018 · 997 hits

我有一批字符串,规律是“数字 + 字母 + 数字 + 字母 + 数字”,数字和字母可以是任意一个或多个,如:1A03F4F、16DC203B5R。我想要正则提取开头的第一段数字、第一段字母、第二段数字、第二段字母等,请教大家该怎么写?

string.scan(/(\d+)([a-z]+)/i)

Reply to luikore

我想要的是分别将第一段数字、第一段字母、第二段数字、第二段字母提取出来,这个好像实现不了啊

'16DC203B5R'.scan(/(\d+)([a-zA-Z]+)/)
=> [["16", "DC"], ["203", "B"], ["5", "R"]]
Reply to luikore

可以实现,我看错了,谢谢!

5 Floor has deleted

可以实现,谢谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.