AnsweredAssumed Answered

Parsing text - finding the first occurrence of text after a certain word

Question asked by JeffMurchison on Sep 29, 2013
Latest reply on Sep 30, 2013 by JeffMurchison

Title

Parsing text - finding the first occurrence of text after a certain word

Post

     In my db, I'm grabbing raw order information for my online store and parsing it to create shipping labels. 

     I whipped up a quick script that works very well for most orders, but didn't for some. Here's an excerpt of the raw data for the shipping street:

      

     
          "shipping_street": "123 Fake St\n\n", "total":
      
      
     And here's the short script that whittles it down to just the info I need:
      
     
          Let ( [ T = GetLayoutObjectAttribute ( "tindieorder-api" ; "Content" ) ;
     
                    start = Position ( T ; "shipping_street" ; 1; 1 ) + 19;
     
                    end =  Position ( T ; "\"," ; 1; 16 ) +2
     
                  ] ;
     
           
     
          Substitute ( Middle ( T ; start ; (end - start) ) ; ["\n\n\"," ; ""] ; ["\n\"," ; ""] ; ["\"," ; ""] ; ["\n" ; ¶ ] ) 
     
          )
     
           

     As you can see, the script looks for shipping_street and then looks for the 16th instance of  ",  and then performs some substitution to fix carriage return characters.

     Now, I figured out the reason it doesn't work on all orders is because the  ",  after  shipping_street  isn't always the 16th occurrence.

     Basically what I need to find is a way to get all the info between shipping_street and the first  ",  after it. Obviously the address will be a variable length as well. Does anyone have any suggestions? Also if I didn't explain that well enough just let me know.

Outcomes