尝试使用gsub
以转换字符串的顺序同意字符以及字符的组合'qu'
。如何通过正则表达式声明((two specific character in a specific order) OR (any character in a set of characters)) any number of times
我尝试了以下方法无济于事:
"stupid".gsub( /([(qu)]*[^aeiou]*)(.*)/, '\2\1') + 'ay' #=> "upidstay" correct!
"uce".gsub( /([(qu)]*[^aeiou]*)(.*)/, '\2\1') + 'ay' #=> "eucay" NOT correct :(
"stupid".gsub( /((qu)*[^aeiou]*)(.*)/, '\2\1') + 'ay' #=> "stay"
"uce".gsub( /([(qu)|[^aeiou]]*)(.*)/, '\2\1') + 'ay' #=> "eucay" # why does just a "u" match?
我认为归根结底是我不知道如何在 中选择多个特定的连续字符[]
,我以为是,[(qu)]
但为什么只是u
匹配?