(对不起标题,任何建议表示赞赏);-)
好吧,考虑那些字符串:
first = "SC/SCO_160ZA206_T_mlaz_kdiz_nziizjeij.ext" second = "MLA/SA2_jkj15PO_B_lkazkl lakzlk-akzl.oxt" third = "A12A/AZD_KZALKZL_F_LKAZ_AZ__azaz___.ixt"我正在寻找一个正则表达式,可以让我得到像这样的数组(在ruby中):
first_array = ['SCO', '160ZA206', 'T', 'mlaz_kdiz_nziizjeij'] second_array = ['SA2', 'jkj15PO', 'B', 'lkazkl lakzlk-akzl'] third_array = ['AZD', 'KZALKZL', 'F', 'LKAZ_AZ__azaz___']第一场比赛必须是在第一场比赛之后,
第二场比赛必须是第一场和第二场之间的任何比赛_
第三场比赛必须是第二场比赛和第三场比赛之间的任何比赛
最后一场比赛必须是第三场比赛和最后一场比赛.
我无法得到它: [^\/].?([AZ]*)_(.*)_(.*)[\.$] :-(
(Sorry for the bad title, any suggestion appreciated) ;-)
Well, consider those strings:
first = "SC/SCO_160ZA206_T_mlaz_kdiz_nziizjeij.ext" second = "MLA/SA2_jkj15PO_B_lkazkl lakzlk-akzl.oxt" third = "A12A/AZD_KZALKZL_F_LKAZ_AZ__azaz___.ixt"I'm looking for a regular expression allowing me to get arrays like this (in ruby):
first_array = ['SCO', '160ZA206', 'T', 'mlaz_kdiz_nziizjeij'] second_array = ['SA2', 'jkj15PO', 'B', 'lkazkl lakzlk-akzl'] third_array = ['AZD', 'KZALKZL', 'F', 'LKAZ_AZ__azaz___']The first match must be anything right after the / and before the first _
The second match must be anything between the first and the second _
The third match must be anything between the second and the third _
The last match must be anything between the third _ and the last .
I can't get it: [^\/].?([A-Z]*)_(.*)_(.*)[\.$] :-(
最满意答案
你超级密切。 只需向第二个匹配器添加一个问号以使其懒惰(否则,它不会停在第一个下划线处),然后复制该匹配器。
[^\/].?([A-Z]*)_(.*?)_(.*?)_(.*)[\.$]You're super close. Just add a question mark to the second matcher to make it lazy (otherwise, it won't stop at the first underscore), and then duplicate that matcher.
[^\/].?([A-Z]*)_(.*?)_(.*?)_(.*)[\.$]更多推荐
发布评论