Preg_match Alpha "'_-sayısal ve beyaz boşluk

2 Cevap php

Ben bu birkaç çatlaklar vardı ama doğru almak gibi olamaz. Herkes bir "_ ve-alphanumerics izin regex, 'yanı sıra, beyaz boşluk var.

Thx

2 Cevap

Bunu dene:

/^[A-Za-z0-9-_",'\s]+$/

Ben regex içindeki \ s bayrağı üzerinde oldukça çok okudum, ben ancak o \ s bayrağı metakarakterleriyle tüm maçları ve ayrıca satır sonlarını atlar görünmektedir her stackoverflow üzerinde şeker gibi dağıttı bakın.

Bu yazılım, web sitesi veya veritabanında istemediğiniz karakterleri her türlü süzülmüş kullanıcı girişi görmezden sağlayacaktır.

\ S bayrağı da dahil savunmasız süzülmüş kodunu bırakarak yeni hat sonları böylece lol hack kendi risk aksi mutlu bu yöntemi kullanmak atlar ...

/[^\p{Xan}]++$/D: Bu gibi bir şey düşünebilirsiniz

  • \p{Xan} matches all unicode alphabet letters and numbers, if this
    doesn't allow all alphabet white space then I am unsure how to safly match these for a filter.

  • ++ makes use of the possessive quantifier that can help optimize the match

  • $/D causes the regex to terminate at the end of the string and not skip over any characters before a line break

\ s bayrak:

Ref: http://php.net/manual/en/reference.pcre.pattern.modifiers.php

s (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

Metakarakter:

Ref: http://en.wikipedia.org/wiki/Metacharacter

A metacharacter is a character that has a special meaning (instead of a literal meaning) to a computer program, such as a shell interpreter or a regular expression engine.

In regular expressions, there are 11 metacharacters that must always be preceded by a backslash, \, to be used inside of the expression:

The opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ).[1]

If you want to use any of these characters as a literal in a regex, you need to escape them with a backslash. If you want to match 1+1=2, the correct regex is 1+1=2. Otherwise, the plus sign will have a special meaning.