5

I need to write a regular expression so I could replace the invalid characters in user's input before sending it further. I think i need to use string.replaceAll("regex", "replacement") to do that. The particular line of code should replace all characters which are not unicode letters. So it's a white list of unicode characters. Basically it's validating and replacing the invalid characters of user's first name.

What I've found so far is this: \p{L}\p{M}, but I'm not sure how to fire it up in regexp so it would work as I explained above. Would this be a regex negation case?

4

2 に答える 2

9
于 2011-06-27T14:13:13.897 に答える
2

Javaのデフォルトの正規表現ライブラリ(JNIが必要ですが、ICUへのリンクの外で読むことをお勧めします)がこれに必要なUnicodeプロパティをサポートしているとは思いません。

もしそうなら、あなたは\p{Diacritic}あなたのパターンに含めるでしょう。ただし、そのためには完全なプロパティ サポートが必要です。

私はあなたが撃つことができると思いますが(\pL\pM*)+、それはさまざまな分音符号のために失敗します: 誰かの名がただではÉtoileなくL’étoile?

また、人々の名前を検証する問題は事実上解決できないと考えられていたため、 RFC 3454 の「stringprep」アルゴリズムに従ってクリーンアップされた、好きなものを使用できるようにする必要があると考えました。

于 2011-06-27T14:12:08.530 に答える