2017-06-27 17 views
0

すべての文字を除いた文字や数字を選択します。正規表現は、私は、この正規表現を持っている

私は

[a-zA-Z0-9] 

を使用する場合はマッチが正しく数字と文字です。私はそれを否定する必要がありますが、^は機能しません。あなたは括弧の中^を置く必要があります否定する

+0

'^ 'は、無効にする文字グループ内にある必要があります。 '[^ a-zA-Z] – marekful

+0

[正規表現での文字の否定]の可能な複製(https://stackoverflow.com/questions/1763071/negate-characters-in-regular-expression) – Soviut

答えて

1

以下は、正規表現の簡単な概要と、以下のコマンドを使用してクエリセットをグループ化する方法です。あなたの場合は[a-zA-Z0-9]の中に^を置き、希望の結果を達成してください。

. Single character match except newline 
    "." Anything in quotations marks literally 
    A* Zero or more occurrences of A 
    A+ One or more occurrences of A 
    A? Zero or one occurrence of A 
    A/B Match A only if followed by B 
() series of regexps grouped together 
    [] Match any character in brackets 
    [^] Do not match any character in brackets 
    [-] Define range of characters to match 
^ Match beginning of new line 
    $ Match end of a line 
    {} Cardinality of pattern match set 
    \ Escapes meta-characters 
    | Disjunctive matches, or operation match 
1

は、あなたの表現の開始時に^を置くと、「文字列の先頭から検索」を意味します。あなたはそれを否定にするために角括弧の中に置く必要があります。

[^a-zA-Z0-9] 
関連する問題