关于正则的简单问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 08:12:25
谁能告诉我在什么情况下正则中的"^"表示除了...之外,什么时候表示以...开头,还有"-"是什么意思?最好举个例子,在线等,急!!!答的通俗易懂全面的当场给分!
如果我想表示除了a之外的所有字符是不是得[^a],得把这个a放字符集里^才能生效?否则^a就表示以a开头?

^a 表示以a 开头

[^a]表示除了a的任何字符

[a-zA-Z] a 到 z 或 A 到 Z,两头的字母包括在内(范围)

java doc文档里 Pattern 类里面有详细的介绍

^a就表示以a开头

LZ的E文不知如何,下面就是JAVASCRIPT的全部解释,其它语言的正则表达式也类似.

Character Meaning
\ For characters that are usually treated literally, indicates that the next character is special and not to be interpreted literally. For example, /b/ matches the character 'b'. By placing a backslash in front of b, that is by using /\b/, the character becomes special to mean match a word boundary.-or-For characters that are usually treated specially, indicates that the next character is not special and should be interpreted literally. For example, * is a special character that means 0 or more occurrences of the preceding character should be matched; for example, /a*/ means match 0 or more a's. To match * literally, precede the it with a backslash; for example, /a\*/ matches 'a*'.
^ Matches beginning of input or line.F