日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用split进行分割时遇到特殊字符的问题

發(fā)布時間:2025/4/5 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用split进行分割时遇到特殊字符的问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用split分割時:

String[] a="aa|bb|cc".split("|");output: [a, a, |, b, b, |, c, c]

先看一下split的用法:

String[] java.lang.String.split(String regex)Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex Result : { "boo", "and", "foo" }} o { "b", "", ":and:f" }} Parameters: regex the delimiting regular expression Returns: the array of strings computed by splitting this string around matches of the given regular expression Throws: PatternSyntaxException - if the regular expression's syntax is invalid Since: 1.4 See Also: java.util.regex.Pattern @spec JSR-51

可以看到split中參數(shù)是一個正則表達式,正則表達式中有一些特殊字符需要注意,它們有自己的用法:

http://www.fon.hum.uva.nl/praat/manual/Regular_expressions_1__Special_characters.html

The following characters are the meta characters that give special meaning to the regular expression search syntax:\ the backslash escape character. The backslash gives special meaning to the character following it. For example, the combination "\n" stands for the newline, one of the control characters. The combination "\w" stands for a "word" character, one of the convenience escape sequences while "\1" is one of the substitution special characters.Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself.Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the start of line anchor or the negate symbol.Example: "^a" matches "a" at the start of a line.Example: "[^0-9]" matches any non digit. $ the dollar is the end of line anchor.Example: "b$" matches a "b" at the end of a line.Example: "^b$" matches the empty line. { } the open and close curly bracket are used as range quantifiers.Example: "a{2,3}" matches "aa" or "aaa". [ ] the open and close square bracket define a character class to match a single character. The "^" as the first character following the "[" negates and the match is for the characters not listed. The "-" denotes a range of characters. Inside a "[ ]" character class construction most special characters are interpreted as ordinary characters.Example: "[d-f]" is the same as "[def]" and matches "d", "e" or "f".Example: "[a-z]" matches any lowercase characters in the alfabet.Example: "[^0-9]" matches any character that is not a digit.Example: A search for "[][()?<>.*?]" in the string "[]()?<>.*?" followed by a replace string "r" has the result "rrrrrrrrrrrrr". Here the search string is one character class and all the meta characters are interpreted as ordinary characters without the need to escape them. ( ) the open and close parenthesis are used for grouping characters (or other regex). The groups can be referenced in both the search and the substitution phase. There also exist some special constructs with parenthesis.Example: "(ab)\1" matches "abab". . the dot matches any character except the newline.Example: ".a" matches two consecutive characters where the last one is "a".Example: ".*\.txt$" matches all strings that end in ".txt". * the star is the match-zero-or-more quantifier.Example: "^.*$" matches an entire line. + the plus is the match-one-or-more quantifier. ? the question mark is the match-zero-or-one quantifier. The question mark is also used in special constructs with parenthesis and in changing match behaviour. | the vertical pipe separates a series of alternatives.Example: "(a|b|c)a" matches "aa" or "ba" or "ca". < > the smaller and greater signs are anchors that specify a left or right word boundary. - the minus indicates a range in a character class (when it is not at the first position after the "[" opening bracket or the last position before the "]" closing bracket.Example: "[A-Z]" matches any uppercase character.Example: "[A-Z-]" or "[-A-Z]" match any uppercase character or "-". & the and is the "substitute complete match" symbol.

那么上述方法的解決方法是使用轉(zhuǎn)義來分割:

String[] a="aa|bb|cc".split("\\|");

小結(jié):

對字符串的正則操作時要注意特殊字符的轉(zhuǎn)義。

?

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/4264473.html

總結(jié)

以上是生活随笔為你收集整理的使用split进行分割时遇到特殊字符的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: caopeng在线| 久久婷婷伊人 | 九九这里只有精品视频 | av777777| 91在线视频导航 | 国产97av | 国产午夜福利一区 | 国产又粗又猛又爽又 | 日韩午夜在线观看 | 久久无吗视频 | 亚洲无码精品在线观看 | 久久国产热视频 | 亚洲乱亚洲| 久草aⅴ | 2018av在线 | 亚州欧美日韩 | 久操视频免费在线观看 | 风韵丰满熟妇啪啪区老熟熟女 | 蜜桃成人网 | 日本黄色录象 | 欧洲做受高潮欧美裸体艺术 | 黄色片一区二区三区 | 麻豆黄色网址 | 亚洲激情欧美激情 | 日韩欧美大陆 | 亚洲精品99久久久久中文字幕 | 五月激情六月丁香 | 伊人久久精品一区二区三区 | 妓院一钑片免看黄大片 | 波多野结衣 在线 | 尤物国产 | 日韩一区二区三区精品视频 | 免费一区二区在线观看 | 夜色视频在线观看 | 懂色av中文一区二区三区天美 | 中文毛片无遮挡高潮免费 | 欧美变态口味重另类在线视频 | 新版天堂资源中文8在线 | 国产久精品 | 99精品视频在线观看 | a黄色大片 | 久热精品在线 | 韩国三级与黑人 | 国产又大又长又粗 | 五十路毛片 | 四虎永久在线精品免费一区二区 | 国产永久毛片 | 狠狠鲁视频 | 涩涩综合| 男女操网站 | 91蝌蚪少妇偷拍 | 色网在线免费观看 | 影音先锋日韩资源 | 日韩免费一区二区 | 玖玖成人 | 蜜芽一区二区 | 婷婷伊人五月 | 国产av人人夜夜澡人人爽麻豆 | 青青草免费在线视频 | 久久网站免费看 | 一级二级在线观看 | 福利网址在线观看 | 欧美在线日韩在线 | 成人看| 人操人操| 国产精品成人99一区无码 | 国产偷人 | 天天草天天 | 成人免费片 | 国产一区二区三区免费 | 亚洲中文字幕久久无码 | 丰满人妻妇伦又伦精品国产 | 亚洲一区二区精品 | 亚洲第一成网站 | 久久人人人 | 欧美一区二区三区四区在线观看 | 国产一区二区三区www | 国产一区福利 | 激情丁香| 中国女人真人一级毛片 | 成年人高清视频 | 天天视频天天爽 | 天天综合一区 | av一二区| 麻豆视频在线观看免费网站 | 久久午夜影视 | 精品国模一区二区三区欧美 | 日韩欧美一区二区在线观看 | a在线视频 | 伊人影院视频 | 日韩 欧美 自拍 | 韩日成人| 天堂国产一区二区三区 | 中文字幕在线观看不卡 | 国产免费专区 | 91国偷自产一区二区三区女王 | 久久艹中文字幕 | 伊人365影院 | 国产依人|