2011-08-31 18 views
0

我有一個正則表達式,並在PHP中使用它:我如何使用這個表達式使用JavaScript

(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z])(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»「」‘’])) 

我想它使用JavaScript喜歡使用:

regexp = new Regexep("here that regular expression");

,並檢查:

regexp.text(data)

但我不能這樣做 這行得通。

請幫我 謝謝,

回答

0
var matches = data.match(/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z])(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»「」‘’]))/); 

var regex = /(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z])(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»「」‘’]))/; 
var matches = regex.test(data); 
+0

它不工作。我在谷歌瀏覽器檢查錯誤,並得到:未捕獲的SyntaxError:無效的正則表達式:/( ?ⅰ)\ b((:HTTPS:?| [。] | - [。] \/\ /萬維網\ d {0,3} [A-Z0-9 \] + [AZ])(?: [^ \ S()<>] + | \(([^ \ S()<>] + |(\([^ \ S()<>] + \)))* \))+(?: \(([^ \ S()<>] + |(\([^ \ S()<>] + \)))* \)| [^ \ s'()\ [\] {}!; :'\「。,<>?«»」「'']))/:無效的組 –

相關問題