myString = "THIS THING CAN KISS MY BUTT. HERE ARE MORE SSS";
myNewString = reReplace(myString, "[^0-9|^S{2}]", "|", "All");
myNewString is “|||S||||||||||||SS||||||||||||||||||||||||SSS“
What I want is “||||||||||||||||SS|||||||||||||||||||||||||||” which is what I thought ^S{2} would do (exclude exactly 2 S). Why is it matching any S? Can someone tell me how to fix it? TIA.
actual goal
I’m trying to validate a list of values. Acceptable values would be 6 digit numbers or 5 digit numbers proceeded by SS so 123456,SS12345 is a valid list.
what i’m trying to do is make everything that isn’t SS or a number into a new delimiter because i have no control over the input.
for example 123456 AND SS12345 should be changed to 123456|||||SS12345. after changing the | delimiter to , the result is 123456,SS12345. If a user were to enter 123456 PLUS SS12345 ends up with 123456||||S|SS12345 which = 123456,S,SS12345 which is invalid and the user gets an error, but it should be valid if it didn’t match the single S.
Am I reading this correctly in that you want to replace everything except exactly two consecutive
Scharacters?Is this restricted to a single replace call or can you run it through multiple regex operations? If multiple operations are allowed, it might be easier to run the string through one regex that matches against
S{3,}(to pick up instances of three or moreScharacters) and then through a second one that uses([^S])S([^S])(to pick up singleScharacters). A third run could match against the rest of your rule ([^0-9]).