-2

以下の情報で2つのパターンを生成したい、

1) 次の特殊文字は、アカウント フォームの名、姓、電子メール、電話番号のフィールドに入力できません。

パターン " [ ] : ; | = + * ? < > / \ , 名前をピリオドで始めることはできません

2)次の特殊文字は、会社の住所フィールドに入力できません。

パターン< > / \ |

アイデアをください。

前もって感謝します

4

3 に答える 3

4

これらのパターンを試してください

1点目

(?i)^([a-z][^"\[:\]\|=\+\*\?<>\\\/\r\n]+)$

2点目用

(?i)^([a-z][^<>\\\/\|\r\n]+)$

説明

1st Pattern

"(?i)" +                               -- Match the remainder of the regex with the options: case insensitive (i)
"^" +                                  -- Assert position at the beginning of a line (at beginning of the string or after a line break character)
"(" +                                  -- Match the regular expression below and capture its match into backreference number 1
   "[a-z]" +                              -- Match a single character in the range between “a” and “z”
   "[^\"\\[:\\]\\|=\\+\\*\\?<>\\\\\\/\r\n]" +       -- Match a single character NOT present in the list below
                                             -- The character “"”
                                             -- A [ character
                                             -- The character “:”
                                             -- A ] character
                                             -- A | character
                                             -- The character “=”
                                             -- A + character
                                             -- A * character
                                             -- A ? character
                                             -- One of the characters “&lt;>”
                                             -- A \ character
                                             -- A / character
                                             -- A carriage return character
                                             -- A line feed character
      "+" +                                  -- Between one and unlimited times, as many times as possible, giving back as needed (greedy)
")" +
"$"                                    -- Assert position at the end of a line (at the end of the string or before a line break character)


2nd Pattern

"(?i)" +                  -- Match the remainder of the regex with the options: case insensitive (i)
"^" +                     -- Assert position at the beginning of a line (at beginning of the string or after a line break character)
"(" +                     -- Match the regular expression below and capture its match into backreference number 1
   "[a-z]" +                 -- Match a single character in the range between “a” and “z”
   "[^<>\\\\\\/\\|\r\n]" +       -- Match a single character NOT present in the list below
                                -- One of the characters “&lt;>”
                                -- A \ character
                                -- A / character
                                -- A | character
                                -- A carriage return character
                                -- A line feed character
      "+" +                     -- Between one and unlimited times, as many times as possible, giving back as needed (greedy)
")" +
"$"                       -- Assert position at the end of a line (at the end of the string or before a line break character)

コード

try {
    boolean foundMatch = subjectString.matches("(?i)^([a-z][^\"\\[:\\]|=+*?<>\\\\/\\r\\n]+)$");
} catch (PatternSyntaxException ex) {
    // Syntax error in the regular expression
}
于 2012-05-26T12:13:29.793 に答える
1

以下は私の問題の解決策です

1)(?i)^([az] [^ \ "\ [:\] | = + *。?<> \\ / \ r \ n] +)$

2)(?i)^([az] [^ \ "<> | \\ / \ r \ n] +)$

また、1)名前をピリオド記号で始まらないようにするためのポイントにピリオド記号を追加しました。

CylianとAndyの助けに感謝します、それは本当に私を大いに助けてくれました。

再度、感謝します :)

于 2012-05-26T15:47:25.313 に答える
1

明らかに自信がない正規表現を使用する代わりに、メソッドを使用できますString.contains()

ただし、Mayur Patel が言ったように、正規表現を使用する必要がある場合、" [ab]" は基本的に a または b を意味します。あなたはregularexpressions.infoをチェックする必要があります

于 2012-05-26T11:53:05.157 に答える