Reputation: 113
I have text that I would like to split to the right and left using a delimiter. The text looks something like this:
This is text 10 : 12 More Text Some1 14 : 10 MoreText
Output should be:
This is text | 10 | 12 | More Text
Some1 | 14 | 1 | MoreText
I have this formula but it doesn't work as it's supposed to.
=ARRAYFORMULA(IF(C2:C="","",(SPLIT(REGEXREPLACE(C2:C,"\s*(\d+)\s*","|$1|"),"|"))))
Link to Spreedsheet - https://docs.google.com/spreadsheets/d/1EmL4kzCGxRbwvNJntwMokqgt8yjjAqnZuUidTbZe6Z8/edit?usp=sharing
For example, it outputs the result of the second row above as Some | 1 | 14 | 10 | MoreText
when 1
is part of the Some1
text. I just want the formula to split the text 4 spaces from the colon.
Please help me fix this, will appreciate.
Upvotes: 0
Views: 1837
Reputation: 201713
How about this modification?
In this modification, I modified the regex and replace value of REGEXREPLACE
from your formula.
=ARRAYFORMULA(IF(A1:A="","",(SPLIT(REGEXREPLACE(A1:A,"(\d+) : (\d+)","|$1|$2|"),"|"))))
Myeam 4 5 Team D U18
in your sample might be Myeam 74 15 Team D U18
.In order to remove the space of each cell, how about the following formulas?
=ARRAYFORMULA(IF(A1:A="","",(TRIM(SPLIT(REGEXREPLACE(A1:A,"(\d+) : (\d+)","|$1|$2|"),"|")))))
When I saw your sample input values, I confirmed that 00A0
is used as the space. So if your other sample values have it, please use the following sample formula.
=ARRAYFORMULA(IF(A1:A="","",(TRIM(SPLIT(SUBSTITUTE(REGEXREPLACE(A1:A,"(\d+) : (\d+)","|$1|$2|")," "," "),"|")))))
Upvotes: 1