Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字間に az、AZ、およびスペースのみを許可したい。このために、次の正規表現を使用しています。問題は、先頭と末尾のスペースも許可することです。これを調整して、先頭または末尾の空白を許可しないようにすることはできますか?
[a-zA-Z\\ \\\']*
例 'prince charles' はパスする必要があります ' prince charles' は 先頭の空白が原因で 失敗する必要があります
先頭と末尾の空白を許可しないようにするには、次を使用できます。
^[a-zA-Z](?:[a-zA-Z ]*[a-zA-Z])?$
単語の境界。それはそれと同じくらい簡単です:
^\b[a-zA-Z ]*\b$