On 22 August 2010 14:52, johnwerry <john.we...@gmail.com> wrote: > Trying to get the following gsub call working to replace text of url > with link of the url. I know I have to add slashes, but I am > apparently missing some, somewhere as I can never get it to not error > out. > > txt = txt.gsub(/\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)| > ([^[:punct:]\s]|/)))/,'<a href="#{0}">#{0}</a>'); > > Here is the "add slashes" version of the first parameter, but this > errors out at runtime. What am I missing? > > /\\b(([\\w-] ://?|www[.])[^\\s()<>] (?:\\([\\w\\d] \\)|([^[:punct:]\ > \s]|/)))/ > > -- > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > To post to this group, send email to prototype-scriptacul...@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > >
Can you give some examples, so that we can check the regex. Based upon what you've supplied ... \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))) Options: case insensitive; ^ and $ match at line breaks Assert position at a word boundary «\b» Match the regular expression below and capture its match into backreference number 1 «(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))» Match the regular expression below and capture its match into backreference number 2 «([\w-]+://?|www[.])» Match either the regular expression below (attempting the next alternative only if this one fails) «[\w-]+://?» Match a single character present in the list below «[\w-]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A word character (letters, digits, and underscores) «\w» The character “-” «-» Match the characters “:/” literally «:/» Match the character “/” literally «/?» Between zero and one times, as many times as possible, giving back as needed (greedy) «?» Or match regular expression number 2 below (the entire group fails if this one fails to match) «www[.]» Match the characters “www” literally «www» Match the character “.” «[.]» Match a single character NOT present in the list below «[^\s()<>]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A whitespace character (spaces, tabs, and line breaks) «\s» One of the characters “()<>” «()<>» Match the regular expression below «(?:\([\w\d]+\)|([^[:punct:]\s]|/))» Match either the regular expression below (attempting the next alternative only if this one fails) «\([\w\d]+\)» Match the character “(” literally «\(» Match a single character present in the list below «[\w\d]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A word character (letters, digits, and underscores) «\w» A single digit 0..9 «\d» Match the character “)” literally «\)» Or match regular expression number 2 below (the entire group fails if this one fails to match) «([^[:punct:]\s]|/)» Match the regular expression below and capture its match into backreference number 3 «([^[:punct:]\s]|/)» Match either the regular expression below (attempting the next alternative only if this one fails) «[^[:punct:]\s]» Match a single character NOT present in the list below «[^[:punct:]\s]» A character in the POSIX character class “punct” «[:punct:]» A whitespace character (spaces, tabs, and line breaks) «\s» Or match regular expression number 2 below (the entire group fails if this one fails to match) «/» Match the character “/” literally «/» Created with RegexBuddy -- Richard Quadling. -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.