This question already has an answer here:
I am trying to separate a string into multiple lines based on separator '
but if there's a ?
character before '
I want the data to remain in the same line.
Initial String:
HJK'ABCP?'QR2'SER'
I am able to print the lines like:
HJK'
ABCP?'
QR2'
SER'
But I want the output as:
HJK'
ABCP?'QR2'
SER'
Use this regex
(?<!\?)'
in split funtionYou need a negative lookbehind (http://www.regular-expressions.info/lookaround.html) :
It returns :