I have multiple rows of string where the string is all wrong. Here is one row an an example of the geometry and output expected:
id
geometry
output
1
POLYGON (( 106.812271, -6.361551, 106.812111, -6.361339, 106.81205, -6.361177, 106.81206, -6.360905, 106.812055, -6.360582, 106.812065, -6.360218, 106.812293, -6.359295, 106.812593, -6.358644, 106.812436, -6.358406, 106.8121515, -6.3582051, 106.8123, -6.357823, 106.81244, -6.357407, 106.812612, -6.356842, 106.812719, -6.356544, 106.81274, -6.356384, 106.812864, -6.356148, 106.813019, -6.356021, 106.813287, -6.355797, 106.813781, -6.355286, 106.814076, -6.354751, 106.814277, -6.354393, 106.814403, -6.354027, 106.814553, -6.353814, 106.814736, -6.353526, 106.814993, -6.353302, 106.81516, -6.353024, 106.815358, -6.35279, 106.815509, -6.352588, 106.815675, -6.352331, 106.8153007, -6.3521138, 106.8151398, -6.3520137, 106.8149789, -6.3518005, 106.8147643, -6.3516939, 106.8144639, -6.3516245, 106.8141527, -6.3515392, 106.8135734, -6.351342, 106.813171, -6.3512034, 106.8123284, -6.3509219, 106.8122418, -6.3511298, 106.8118164, -6.3521534, 106.8116597, -6.3525047, 106.8111849, -6.3535692, 106.8102245, -6.3554942, 106.8093545, -6.3568947, 106.8085097, -6.3580518, 106.80795, -6.358832, 106.8077793, -6.3590429, 106.807668, -6.359441, 106.807499, -6.360346, 106.8072531, -6.3616378, 106.8071476, -6.3622599, 106.8070637, -6.3626798, 106.8070823, -6.3629367, 106.8071207, -6.3634531, 106.8078269, -6.363831, 106.809448, -6.364124, 106.810574, -6.364198, 106.81066, -6.362993, 106.811175, -6.36277, 106.812087, -6.361703, 106.812271, -6.361551))
POLYGON (( 106.812271 -6.361551, 106.812111 -6.361339, 106.81205 -6.361177, 106.81206 -6.360905, 106.812055 -6.360582, 106.812065 -6.360218, 106.812293 -6.359295, 106.812593 -6.358644, 106.812436 -6.358406, 106.8121515 -6.3582051, 106.8123 -6.357823, 106.81244 -6.357407, 106.812612 -6.356842, 106.812719 -6.356544, 106.81274 -6.356384, 106.812864 -6.356148, 106.813019 -6.356021, 106.813287 -6.355797, 106.813781 -6.355286, 106.814076 -6.354751, 106.814277 -6.354393, 106.814403 -6.354027, 106.814553 -6.353814, 106.814736 -6.353526, 106.814993 -6.353302, 106.81516 -6.353024, 106.815358 -6.35279, 106.815509 -6.352588, 106.815675, -6.352331, 106.8153007, -6.3521138, 106.8151398 -6.3520137, 106.8149789 -6.3518005, 106.8147643 -6.3516939, 106.8144639 -6.3516245, 106.8141527 -6.3515392, 106.8135734 -6.351342, 106.813171 -6.3512034, 106.8123284 -6.3509219, 106.8122418 -6.3511298, 106.8118164 -6.3521534, 106.8116597 -6.3525047, 106.8111849 -6.3535692, 106.8102245 -6.3554942, 106.8093545 -6.3568947, 106.8085097 -6.3580518, 106.80795 -6.358832, 106.8077793 -6.3590429, 106.807668 -6.359441, 106.807499 -6.360346, 106.8072531 -6.3616378, 106.8071476 -6.3622599, 106.8070637 -6.3626798, 106.8070823 -6.3629367, 106.8071207 -6.3634531, 106.8078269 -6.363831, 106.809448 -6.364124, 106.810574 -6.364198, 106.81066 -6.362993, 106.811175 -6.36277, 106.812087 -6.361703, 106.812271 -6.361551))
One example is as follows above. I need to get rid of all odd position commas and only keep the even position commas. So that the geometry can become output.
I tried doing a split(text.",") and concatenate however when the columns is blank it returns xxx,,,, which is not what I had in mind.
Since some have more than 200 commas means that I need to have more than 200 columns, is there a simpler way like using regex?Someone please help.
If the second number is always negative, this is simple as replacing , - (comma, space, dash) with (space).
=REGEXREPLACE(B2,", -"," ")
If not,
=REGEXREPLACE(B2,"(-??\d+\.?\d*),(\s*-?\d+\.?\d*)","$1$2")
Capture group #1: (-??\d+\.?\d*)
-?? zero or one of literal dash followed by
\d+ one or more digits followed by
.? zero or one of literal .
\d* zero or more of digits
literal ,
Capture group #2 (\s*-?\d+\.?\d*)
\s* zero or more of space characters
-? zero or one of literal dash followed by
\d+ one or more digits followed by
.? zero or one of literal .
\d* zero or more of digits
Replace with capture groups only: $1$2
try:
=INDEX(REGEXREPLACE(QUERY(FLATTEN(SPLIT(A1, ",")&IF(ISODD(
SEQUENCE(1, COLUMNS(SPLIT(A1, ",")))),, ",")),,9^9), ",$", ))
for array:
=INDEX(IFERROR(BYROW(A1:A3, LAMBDA(x, REGEXREPLACE(QUERY(FLATTEN(SPLIT(x, ",")&
IF(ISODD(SEQUENCE(1, COLUMNS(SPLIT(x, ",")))),, ",")),,9^9), ",$", )))))
An idea to match , and capture any non-commas with an optional comma after:
=REGEXREPLACE(A1; ",([^,]*,?)"; "$1")
Replace with $1 what was captured by the first group - See this demo at regex101
I need a regex that accepts all the strings consisting only of characters a and b, except those with more than two 'b' in a row.
For example, these should not match:
abb
ababbb
bba
bbbaa
bbb
bb
I came up with this, but it's not working
[a-b]+b{2,}[a-b]*
Here is my code:
int main() {
string input;
regex validator_regex("\b(?:b(?:a+b?)*|(?:a+b?)+)\b");
cout << "Hello, "<<endl;
while(regex_match(input,validator_regex)==false){
cout << "please enter your choice of regEx :"<<endl;
cin>>input;
if(regex_match(input,validator_regex)==false)
cout<<input+" is not a valid input"<<endl;
else
cout<<input+" is valid "<<endl;
}
}
Your pattern [a-b]+b{2,}[a-b]* matches 1 or more a or b chars until you match bb which is what you don't want. Also note that the string should be at least 3 characters long due to this part [a-b]+b{2,}
To not match 2 b chars in a row you can exclude those matches using a negative lookahead by matching optional chars a or b until you encounter bb
Note that [a-b] is the same as [ab]
\b(?![ab]*?bb)[ab]+\b
\b A word boundary
(?![ab]*?bb) Negative lookahead, assert not 0+ times a or b followed by bb to the right
[ab]+ Match 1+ occurrences of a or b
\b A word boundary
Regex demo
Without using lookarounds, you can match the strings that you don't want by matching a string that contains bb, and capture in group 1 the strings that you want to keep:
\b[ab]*bb[ab]*\b|\b([ab]+)\b
Regex demo
Or use an alternation matching either starting with b and optional repetitions of 1+ a chars followed by an optional b, or match 1+ repetitions of starting with a followed by an optional b
\b(?:b(?:a+b?)*|(?:a+b?)+)\b
Regex demo
The simplest regex is:
^(?!.*bb)[ab]+$
See live demo.
This regex works by adding a negative look ahead (anchored to start) for bb appearing anywhere within input consisting of a or b.
If zero length input should match, change [ab]+ to [ab]*.