I have a following String:
MYLMFILLAAGCSKMYLLFINNAARPFASSTKAASTVVTPHHSYTSKPHHSTTSHCKSSD
I want to split such a string every time a K or R is encountered, except when followed by a P.
Therefore, I want the following output:
MYLMFILLAAGCSK
MYLLFINNAARPFASSTK
AASTVVTPHHSYTSKPHHSTTSHCK
SSD
At first, I tried using simple .split() function in java but I couldn't get the desired result. Because I really don't know how to mention it in the .split() function not to split if there is a P right after K or R.
I've looked at other similar questions and they suggest to use Pattern matching but I don't know how to use it in this context.
**K**,**P**etc as text? Or did you put them in bold for us to see them?charAt()if it contains K or R alone and then usesubstring()and the positions found to split your string.