I have some strings Like
1.IND_FROM_ONE_TO_FIVE
2.IND_FROM_FIVE_TO_TEN
3.BS_FROM_ONE_TO_FIVE
4.BS_FROM_FIVE_TO_TEN
5.OP_FROM_ONE_TO_FIVE
6.OP_FROM_FIVE_TO_TEN
And I want to cut from all of them everything before the first "" include ""!!!.
Something like :
1.IND_FROM_ONE_TO_FIVE => FROM_ONE_TO_FIVE
2.IND_FROM_FIVE_TO_TEN => FROM_FIVE_TO_TEN
3.BS_FROM_ONE_TO_FIVE => FROM_ONE_TO_FIVE
4.BS_FROM_FIVE_TO_TEN => FROM_FIVE_TO_TEN etc.
I have tried /[^_]*/
but it returns IND_FROM_ONE_TO_FIVE => _FROM_ONE_TO_FIVE
(did not cut first "_")
How could I make it on java?
You can prepend an anchor and match the underscore after is as well. In the replacement use an empty string.
^[^_]*_
Using replaceFirst you can omit the anchor:
System.out.println("IND_FROM_ONE_TO_FIVE".replaceFirst("[^_]*_", ""));
Output
FROM_ONE_TO_FIVE
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加