-1

これはバリデーター npm モジュールからスクレイピングされた URL バリデーターです。私は正規表現を初めて使用します。これをデコードするのを手伝ってくれる人はいますか? そして、おそらくURLの一致と不一致について言及していますか?

(/^(?!mailto:)(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:\/[^\s]*)?$/i)
4

3 に答える 3

1

これは、文書化された URL (および IP アドレス) 標準をできるだけ多く取得するように設計された URL バリデーターです。

それについて学び、さまざまな一致をテストするために、 regex101.comに追加することをお勧めします。

これは、試してみるための例です。テスト文字列の URL を変更するだけで、結果が表示されます。http://regex101.com/r/jQ1lZ5

一致するいくつかの例:

一致しないもの:

  • wwww..google.com
  • http:://www.google.com
  • 12.20.140.256 (有効な IP アドレスではありません!)
  • ローカル ホスト
于 2013-11-27T17:28:15.193 に答える
0

あなたは確かに正規表現について読む必要があります。とにかく、ここにいくつかのヒントがあります(網羅的ではありません):

^ : out of a class it matches the beginning of a string
^ : in a class it makes your class a negation class
$ : matches the end of a string
() : creates group which could be reusable, quantifiable, etc.
? : tells the last character or group can be present once or not present
+ : tells the last character or group is present at least once
* : tells the last character or group can be present once or more or not present
\ : escape the following char. Usefull is you have to match a character which is also a metacharacter 
| : is for alternative 
{x, y} : allow you to quantify more precisely than *, ? or +
[] : allow you to create class. [abc] is equivalent to a|b|c
? : after a + or * make it non greedy. By default quantifier are greedy (match the langest string possible)
于 2013-11-27T17:35:23.173 に答える
-1

コンピューティングでは、正規表現 (略して regex または regexp) は検索パターンを形成する一連の文字であり、主に文字列とのパターン マッチング、または文字列マッチング、つまり「検索と置換」のような操作で使用されます。この概念は 1950 年代にアメリカの数学者 Stephen Kleene が正規言語の記述を形式化したときに生まれ、Unix テキスト処理ユーティリティの ed、エディター、および grep (グローバル正規表現プリント)、フィルターで一般的に使用されるようになりました。

http://en.wikipedia.org/wiki/Regular_expression

于 2013-11-27T17:21:03.160 に答える