I have strings like
A_B_C_D
A_B___C_D
where the ___could be anywhere in the string.
What is the easiest way to split them at any single _ but not at ___?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Instead of finding the separators, we find the components themselves. Notice that the strings must be either non-
_‘s (because the separator is_), or more than one_s. So the regex to match them is simply like this.Note that this regex ignores the empty strings if the input starts or ends with
_(e.g."_a_"will just return["a"].)