1. 程式人生 > >Everyday try to become batter -Kobe Bryant

Everyday try to become batter -Kobe Bryant

那麼這裡在列上一些轉義字元

 \\ 反斜槓 
\t 間隔 ('\u0009')
\n 換行 ('\u000A')
\r 回車 ('\u000D')
\d 數字 等價於 [0-9]
\D 非數字 等價於 [^0-9]
\s 空白符號 [\t\n\x0B\f\r]
\S 非空白符號 [^\t\n\x0B\f\r]
\w 單獨字元 [a-zA-Z_0-9]
\W 非單獨字元 [^a-zA-Z_0-9]
\f 換頁符 
\e Escape
\b 一個單詞的邊界 
\B 一個非單詞的邊界 
\G 前一個匹配的結束

------------------------------------------------------------------------------------

我在應用中用到一些給大家總結一下僅供大家參考

1、如果用“.”作為分隔的話必須是如下寫法String.split("\\."),這樣才

能正確的分隔開不能用String.split(".");

2、如果用“|”作為分隔的話必須是如下寫法String.split("\\|"),這樣才

能正確的分隔開不能用String.split("|");

“.”和“|”都是轉義字元必須得加"\\";

3、如果在一個字串中有多個分隔符可以用“|”作為連字元比如“acount=?

and uu =? or n=?”,把三個都分隔出來可以用String.split("and|or");

使用String.split方法分隔字串時分隔符如果用到一些特殊字元可能會

得不到我們預期的結果。 

我們看jdk doc中說明  

public String[] split(String regex)

 Splits this string around matches of the given regular expression. 

引數regex是一個 regular-expression的匹配模式而不是一個簡單的String

他對一些特殊的字元可能會出現你預想不到的結果比如測試下面的程式碼

用豎線 | 分隔字串你將得不到預期的結果

    String[] aa = "aaa|bbb|ccc".split("|");

    //String[] aa = "aaa|bbb|ccc".split("\\|"); 這樣才能得到正確的結果

    for (int i = 0 ; i <aa.length ; i++ ) {

      System.out.println("--"+aa[i]); 

    } 

用豎 * 分隔字串執行將丟擲Java.util.regex.PatternSyntaxException異

常用加號 + 也是如此。

    String[] aa = "aaa*bbb*ccc".split("*");

    //String[] aa = "aaa|bbb|ccc".split("\\*"); 這樣才能得到正確的結

果    

    for (int i = 0 ; i <aa.length ; i++ ) {

      System.out.println("--"+aa[i]); 

    }  顯然+ * 不是有效的模式匹配規則表示式用"\\*" "\\+"轉義後即可得到正

確的結果。

"|" 分隔串時雖然能夠執行但是卻不是預期的目的"\\|"轉義後即可得到正

確的結果。

還有如果想在串中使用"\"字元則也需要轉義.首先要表達"aaaa\bbbb"這個串

就應該用"aaaa\\bbbb",如果要分隔就應該這樣才能得到正確結果

String[] aa = "aaa\\bbb\\bccc".split("\\\\");

轉自:http://blog.csdn.net/lanchengxiaoxiao/article/details/41893925

相關推薦

Everyday try to become batter -Kobe Bryant

那麼這裡在列上一些轉義字元  \\ 反斜槓  \t 間隔 ('\u0009') \n 換行 ('\u000A') \r 回車 ('\u000D') \d 數字 等價於 [0-9] \D 非數字 等價於 [^0-9] \s 空白符號 [\t\n\x0B\f\r] \S 非

kubeadm init 卡在 Created API client, waiting for the control plane to become ready

mon issues https res 出現 blog ted col journal 執行 kubeadm init 時出現卡在了 [apiclient] Created API client, waiting for the control plane to beco

8 Ways to Become a Better Coder

tac block fin iou cau pla super fail rsquo It’s time to get serious about improving your programming skills. Let’s do it! Th

How to become a excellent programmer?

How to become a excellent programmer? Add comments to your code Do not complicate things Keep in Mind ----“Less is more” is not always

How to become a successful bug bounty hunter

如果你夢想成為賞金獵人,你的夢想就會成真 - 不要把你的名字變成“狗”或者在Mos Eisley酒吧面對Han Solo。 成為一個bug賞金獵人:一個有錢尋找軟體和網站漏洞的黑客。 任何具有計算機技能和高度好奇心的人都可以成為漏洞的成功者。 你開始時可以年輕或年老。 主要要求是你需要不斷學習。 此外,如果

ichunqiu--try to pwn.md

ichunqiu–try to pwn 好吧,這個題目其實還沒有做到我想要的地步,我還想再深度挖掘一下,但是週末了,該寫writeup了,就先把這部分總結寫了,之後如果還想有其他的嘗試,就繼續做吧。 題目又不是我自己做出來的,當時沒有發現程式的溢位點,於是就到

ichunqiu-try to pwn-II.md

FSP-stack pivot-ROP-try to pwn-II 上次(這裡放上次的文章連結)由於時間原因,比較倉促、敷衍的完成了一篇大致的writeup 但是其中還有很多的問題存在;這篇writeup旨在解決遇到的很多問題、疑惑;此外,還向別人請教了一些知

More reading and learning to become excellent

在C語言中,使用Point(指標)可以間接獲取,修改某個變數的值 在C++中,使用引用(Reference),可以起到跟指標類似的功能. 注意點: 引用相等於是變數的別名(基本資料型別,列舉,結構體,

try to install CPAN and list installed rpm packages

[[email protected] example]$ pwd /home/arthur/BGA2017/Course_material/circos-0.69-6/example [[email protected] example]$ cd ../.

LandGrey-On the way to become a hacker

0x01: 前臺指令碼檢測副檔名—繞過 原理 當用戶在客戶端選擇檔案點選上傳的時候,客戶端還沒有向伺服器傳送任何訊息,就對本地檔案進行檢測來判斷是否是可以上傳的型別,這種方式稱為前臺指令碼檢測副

How to become a Git expert

Scenario 1Let’s say that you have committed a bunch of files and realised that the commit message you entered is actually not clear. Now you want to change

Ask HN: What are the absolute essentials to become a software developer

I am a mathematician who wants to get into software development. What are the absolute essentials bits to know from theory, application and coding guidelin

 How 3 European nations are planning to become blockchain…

Honorable mention: France’s new crypto regulationsource: cointelegraphWith somewhat of a late response, the French regulator is en route to introduce a set

How to become a machine learning engineer: A cheat sheet

Machine learning engineers--i.e., advanced programmers who develop artificial intelligence (AI) machines and systems that can learn and apply knowledge--ar

Jonathan Hoppe Opening Keynote: How to Become a DX Hero @TotalUptime #Cloud #DX #CIO #DigitalTransformation

Organizations realize the tremendous benefits of everything the digital transformation has to offer. Cloud adoption rates are increasing significantly, and

Top Machine Learning Algorithms You Should Know to Become a Data Scientist

There are two ways to categorize Machine Learning algorithms you may come across in the field. Generally, both approaches are useful. However, we will focu

(Deliberate) practice makes perfect: how to become an expert in anything

(Deliberate) practice makes perfect: how to become an expert in anythingOriginally published on JOTFORM.COMThe human race is out-doing itself.We’re faster,

How to become a team with chatbots

How to become a team with chatbotsBol.com, a well-known e-commerce platform in The Netherlands and Belgium, serves nearly 8.5 million active customers. For

How to become a Conversation Designer and make chatbots and voice assistants more helpful, natural…

How to become a Conversation Designer and make chatbots and voice assistants more helpful, natural and persuasiveConversation Design is a new job. The Conv

Gartner Says Robotics To Become Mainstream In Finance Departments By 2020

Corporate controllers are set to dramatically increase their adoption of robotic process automation (RPA), according to new research by Gartner, Inc. Today