This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a stringpattern like this: (--Select--)|(word1)|(word2)|(word3), it can has more or less word, for example:
I want to get the "word" and put them in a String, desired result would be like pattern = --select--, pattern = Business, pattern= Personal, I tried String.replace and String.split to get rid of "|, (, )", but did not work out. When I used , in stead of getting (--Select--), (Business) and (Personal), I got 35 strings. Please help to figure out how to solve this.
The split() method takes a regular expression. And in a regular expression, the "|" has special meaning. If you want it to mean the literal "|" (ie. disable the meaning), then you need to escape it... like so...