0
夠搞笑(或沒有)在Java中比賽VAR值爲true,但是在android系統它不:java和android之間的模式匹配差異?
CharSequence target = "man on";
boolean match = target.toString().matches("(\\p{L}\\p{L}+-?\\s?\\p{L}+)+");
任何想法,爲什麼出現這種情況?
謝謝。
聚苯乙烯:我通過導入和使用Matcher工作。
Pattern pattern = Pattern.compile("(\\p{L}\\p{L}+-?\\s?\\p{L}+)+");
Matcher matcher = pattern.matcher(target);
然後matcher.matches()在「man on」上的計算結果爲true。
爲什麼你在'String'上調用'toString'? – fabian
必須是android實現'String.matches'的方式,因爲基本上只是內聯了'String.matches'在第二種情況下的工作方式(http://grepcode.com/file/repository.grepcode.com /java/root/jdk/openjdk/6-b14/java/lang/String.java#2101) –
@fabian:對不起,我在這裏粘貼了代碼,編輯得很差。在Android應用程序中沒有 'String target =「man on」' 目標實際上是一個CharSequence .. :) 其實我只是測試它,第二個適用於「man on」,但不適用「moon on man」 。 ()+或?應該是這種情況。 當然在browxy.com上 'boolean bla = args [0] .toString()。matches(「(\\ p {L} \\ p {L} + - ?\ s?\\ p {L } +)+「);' 甚至適用於」月球上的男人bla魚「.. – cristian