2013-11-21 52 views

回答

1

你可以使用這個表達式:

"(?<=\s)[^|]*" 
+0

謝謝你anubhava 其工作精細 – user518363

+0

不客氣,很高興它爲你工作。如果它對您有幫助,請考慮將其標記爲「已接受」。 – anubhava

0

使用正則表達式:

/\ ([^ \|]*)\|/ 

您可以在Rubular

4

測試這個正則表達式可以使用這一個:

(?<=\s)[^\|]*(?=\|) 

Anubhava的答案也是正確的,但在

String : "Helllo good day |on a go|there you are" 
Match : "good day ", "a go", "you are"   // Anubhava's 
Match : "good day ", "a go"      // this one 

// "you are" should not be matched as not in between space and |. | is not there at the end 

情況下,這個正則表達式有三個部分:

  • (?<=\s):看回一個格
  • [^\|]*:任何事情比其他|
  • (?=\|):預見|

所以,一起(?<=\s)[^\|]*(?=\|)將匹配收到了space()序列,和之後的|,而不將它們包括在匹配。

您可以test the regex here

+0

謝謝牛仔布...... – user518363

+0

多一個幫助牛仔布。在空間和|之間,應該匹配的字符數應該只有3 .. – user518363

+0

@ user518363:抱歉,沒有弄到你。你能否詳細說明一下。 –

相關問題