如何才能将{}
中包含的单个单词从文本
an example of the text {Creating|Making|Producing} blah blah blah
或
another example of the text {{In order to|As a way to|So that you can|To be able to} {connect|link|join}} blah blah blah
凭借我有限的正则表达式知识,我已经掌握了这一点
text.scan(/{([^}]*)}/)[0][0].split('|')
但是这会选择文字{In order to|As a way to|So that you can|To be able to
并将其拆分为{In order to
如何仅在{}
?
预期输出
["In order to", "As a way to", "So that you can", "To be able to"]
谢谢!
答案 0 :(得分:2)
尝试:
text.scan(/{([^{}]*)}/)[0][0].split('|')