text.gsub!(/(?<!http:\/\/)www\.(?=\w)/,'http://www.')我have...and说的是未定义的(?)序列。当我在rubular中使用(?<!http:\/\/)www\.(?=\w)时,它做了我想做的事情,但是这对我来说不起作用,所以我需要一些帮助。
这应该是用来代替www. to http://www.的,这是一堂课的作业,所以它必须做到这一点。
非常感谢你的帮助!
发布于 2014-05-06 01:22:47
试试这个:
text.gsub(/^(?!http:\/\/)www(.*?)$/, 'http://www\1')Regex演示
它将www的所有实例(而不是http://前面的实例)替换为http://www.something.com
Regex解释
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!http://)»
Match the characters “http://” literally «http://»
Match the characters “www” literally «www»
Match the regular expression below and capture its match into backreference number 1 «(.*?)»
Match any single character that is not a line break character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Assert position at the end of a line (at the end of the string or before a line break character) «$»https://stackoverflow.com/questions/23484446
复制相似问题