Reputation: 938
I have a very complicated output from a function, which i need to use specific word from it.
For example, my output is:
oracle 11257 1 0 14:01 ? 00:00:00 ora_pmon_sas
I need to get just "sas
" word, which is next to "ora_pmon_
"
Another example:
oracle 6187 1 0 13:41 ? 00:00:00 ora_pmon_db2
I need to get "db2
". So what should be my expression?
JAVA code:
insArray=line.split("what will be between these quotes?");
Upvotes: 0
Views: 163
Reputation: 39443
How about this one?
string = string.replaceAll(".*?ora_pmon_", "");
If you want multiple words in place of ora, then it will be
string = string.replaceAll(".*?(ora|kf|asm)_pmon_", "");
Upvotes: 2
Reputation: 62874
You can simply use String#substring(int i) combined with String#lastIndexOf(char ch)
For example:
String result = input.substring(input.lastIndexOf('_') + 1)
Upvotes: 1
Reputation: 46239
You could just do
String sub = s.substring(s.indexOf("ora_pmon_") + 9);
Upvotes: 2