0

私はAsp.Net/C#自分のプロジェクトで使用しています。電子メール アドレスを検証するために使用しているフォームの 1 つですRegular Expression Validator。電子メールを検証するための例をいくつか検索しました\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* 。どんな説明でも大歓迎です。

ありがとう。

4

1 に答える 1

3

いくつかの短いヒント:

  • \w は単語文字を表します

  • [-+.'] 中括弧内の文字の 1 つ

  • plus と * は量指定子です

  • ( ) 後方参照 (プログラムで参照または読み取ることができるもの) を作成できるグループを囲みます。

より長い (自動化された) 説明:

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Match a single character that is a “word character” (letters, digits, and underscores)     «\w+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below and capture its match into backreference number 1 «([-+.']\w+)*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last  iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match a single character present in the list “-+.'” «[-+.']»
   Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “@” literally «@»
Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below and capture its match into backreference number 2 «([-.]\w+)*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match a single character present in the list “-.” «[-.]»
   Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “.” literally «\.»
Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the regular expression below and capture its match into backreference number 3 «([-.]\w+)*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Note: You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «*»
   Match a single character present in the list “-.” «[-.]»
   Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

RegexBuddy を使用して、より長い自動説明を作成しました

編集:

正規表現に関するスターター情報については、http://www.regular-expressions.info/を参照してください。

于 2012-05-02T06:14:18.953 に答える