-1

Is this a RegEx problem?

To note: there will always be only four items, each starts with a capital letter, each will be in order (color,color,shape,color): "BlackWhiteTriangleGreen" etc.

So,

    a="BlackWhiteTriangleGreen"  

yields:

    c1 = "Black"  
    c2 = "White"  
    S = "Triangle"  
    c3 = "Green"

EDIT: referencing the post suggested by Alex K., an AS3 solution as follows works:

    private function UpperCaseArray(input:String):void {
        var result:String = input.replace(/([A-Z]+)/g, ",$1").replace(/^,/, "");
        var b:Array=result.split(",");
        c1 = b[0];
        c2 = b[1];
        S = b[2];
        c3 = b[3];
    }
6
  • 2
    Possible duplicate of Javascript Split string on UpperCase Characters
    – Alex K.
    Sep 22, 2016 at 13:27
  • /([A-Z][a-z]+)/g Sep 22, 2016 at 13:31
  • @AlexK. Thank you! I looked for an answer, but got scared off by "javascript" answer. Didn't realize they were so similar. Is this the reason why someone voted my question down, do you think?
    – Chowzen
    Sep 22, 2016 at 13:39
  • 1
    Its a common question, the downvotes are probably because its expected that you show what you have already attempted.
    – Alex K.
    Sep 22, 2016 at 13:40
  • 1
    @Chowzen: input_string.match(/([A-Z][a-z]+)/g) Sep 22, 2016 at 14:15

1 Answer 1

2

referencing the post suggested by Alex K., an AS3 solution as follows works:

private function UpperCaseArray(input:String):void {  
    var result:String = input.replace(/([A-Z]+)/g, ",$1").replace(/^,/, "");
    var b:Array=result.split(",");
    c1 = b[0];
    c2 = b[1];
    S = b[2];
    c3 = b[3];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.