开发者

Scanner useDelimiter question

开发者 https://www.devze.com 2023-02-21 03:08 出处:网络
In useDelimiter(\"[^A-Z]+\") what does the ^ 开发者_运维技巧stand for? thanks[^abc]Any character except a, b, or c (negation)

In useDelimiter("[^A-Z]+") what does the ^ 开发者_运维技巧stand for?

thanks


[^abc] Any character except a, b, or c (negation)

From: http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html


Anything except A through Z and only once.


Inside a character class (the [] brackets), the ^ character at the start means that the character class is NOT the following characters

so [0-9] means match any number, [^0-9] means match anything that is NOT a number. [^A] would mean everything but an A and so on.


Inside a character class the ^ negates the meaning of the class if it is the first character in the class (as others have pointed out).

Outside a character class, the ^ is an anchor assertion that matches the (zero-width) location at the beginning of the string (or the location immediately after a \n newline if multi-line mode is on).

0

精彩评论

暂无评论...
验证码 换一张
取 消