Help with regexp (for osc parsing/formatting)

    Apr 01 2011 | 3:23 pm
    Sorry for asking such an explicit 'how do i do this' type question. I'd normally prefer to ask 'what technique should i use to do this'.....
    I have a (osc) message of the form:
    /deviceName/INSTANCE_ID/controlName/CONTROL_INSTANCE_ID data1 data2 data3....etc
    I'd like to pass the address (i.e. first section) of this message through a regexp object such that if the "deviceName" and "controlName" match those expected (i.e. those written into the regexp string) I obtain a max message (list) of the form:
    I know I could do this with [OSC-Route] and a wildcard, but this would produce INSTANCE_ID#s as strings such as "/2". This is no good as the string requires further processing to remove the leading slash to be usable as an integer.
    (For bonus points, I intend to target a pattr object who's scripting name is "controlName[CONTROL_INSTANCE_ID]" - can the regexp format its output like this, or do I still need to run it through a [sprintf %s[%ld] ]?)
    Similarly, does regexp have 'the power' to convert a symbol such as "word[number]" into the following list:
    word number
    (or for more bonus points, into the symbol "word/number" without using [sprintf %s/%ld ])
    Or is there a better object to parse the 'word' and/or 'number' from the symbol "word[number]"?
    Again, apologies for such a direct request. I'll happily accept a link to decent regexp examples/tutorials as an answer (the reference/help files are failing to overcome the mental block I have when it comes to regexes and how these relate to the output produced by regexp)

    • Apr 01 2011 | 10:35 pm
      After some more tinkering (and simplyfying how I was using regexp) I have the following 'solutions' to the two cases I posted about previously.
      Any suggestions/tips/pointers on how to make better use of the regexp objects would be much appreciated
    • Apr 03 2011 | 10:35 am
      After some more work, I now have an abstraction that will convert any pattr path string into an OSC address. Save the patch (e.g. as OSC-address-format) and instantiate objects with an argument to specify your 'address prefix'
      E.g. [OSC-address-format abc]
      will convert:
      Again, as I'm using regexp I'd be grateful if anyone can offer tips to improve how the abstraction implements this functionality
    • Apr 03 2011 | 11:07 am
      And here is the inverse, for parsing an OSC address into a pattr path
    • Apr 03 2011 | 2:43 pm
      After a quick look this looks pretty good, I've not much to add (given that I find regexp a little intimidating at best) except that there are some illustrations/tutorials in the CNMAT MMJ-Depot files (check the CNMAT site) to do with working with OSC and pattr that you may like to check out to compare notes...
    • Apr 03 2011 | 5:34 pm
      This should simplify it a bit for the test cases you have shown in your examples here. I hope it is helpful.