Anonym 53 Posted November 16, 2014 Report Share Posted November 16, 2014 Hmmm... I am a bit rusty ... I have a file that contains the following:and I want to extract this (red) to another variable. These red rows might vary from one case to another so there might be two rows or there might be 30, 50 or even 367. <snip> "english" => array( "descriptions" => array( "button" => "Button Translations", "date" => "Date & Time Translations", ), // UPDATE 27TH JULY 2013 "button" => array( "1" => "Add", "2" => "Edit", "3" => "Delete", ), </snip> If this was a page then I guess I could do something like: set(#myExtractedText, $page scrape("\"descriptions\" => array\\(", "),"), "Global") I have fiddled a lot with regex to try to solve this (reading the file to a variable and then do "$find regular expression" on that variable), but I don't get it right. I am stuck and I would appreciate some help. Thank you! Quote Link to post Share on other sites
Bill 7 Posted November 16, 2014 Report Share Posted November 16, 2014 For a little clarification. The data your trying extract is: "button" => "Button Translations", "date" => "Date & Time Translations", And your saying there could be more rows than just two.Are the rowing your trying to extract the same format as your example? Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted November 16, 2014 Report Share Posted November 16, 2014 one way set(#A, " <snip> \"english\" => array( \"descriptions\" => array( \"button\" => \"Button Translations\", \"date\" => \"Date & Time Translations\", ), // UPDATE 27TH JULY 2013 \"button\" => array( \"1\" => \"Add\", \"2\" => \"Edit\", \"3\" => \"Delete\", ),", "Global") set(#replace, $replace regular expression($find regular expression(#A, "(?<=\").*?(?=\",)"), "\\d.*", $nothing), "Global") CD 1 Quote Link to post Share on other sites
Anonym 53 Posted November 16, 2014 Author Report Share Posted November 16, 2014 For a little clarification. The data your trying extract is: "button" => "Button Translations", "date" => "Date & Time Translations", And your saying there could be more rows than just two.Are the rowing your trying to extract the same format as your example? Yes, there could be one or several rows. Those that are to be extracted are always between "descriptions" => array( and the closing ), The file could look like this: <snip> "english" => array( "descriptions" => array( "button" => "Button Translations", "date" => "Date & Time Translations", "64" => "Numerical label", "mixed_character_label2" => "a label with mixed characters: this text also contains a (, ) and a .", ), // UPDATE 27TH JULY 2013 "button" => array( "1" => "Add", "2" => "Edit", "3" => "Delete", "text_label" => "My string", ), </snip> Quote Link to post Share on other sites
Anonym 53 Posted November 16, 2014 Author Report Share Posted November 16, 2014 one way set(#A, " <snip> \"english\" => array( \"descriptions\" => array( \"button\" => \"Button Translations\", \"date\" => \"Date & Time Translations\", ), // UPDATE 27TH JULY 2013 \"button\" => array( \"1\" => \"Add\", \"2\" => \"Edit\", \"3\" => \"Delete\", ),", "Global") set(#replace, $replace regular expression($find regular expression(#A, "(?<=\").*?(?=\",)"), "\\d.*", $nothing), "Global") CD Thank you! It could be a start. The problem is that it extracts everything, not only what is between: "descriptions" => array( and ), Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted November 16, 2014 Report Share Posted November 16, 2014 put into a list the use ), as the delimiter then use list item 0 then regex set(#A, "<snip> \"english\" => array( \"descriptions\" => array( \"button\" => \"Button Translations\", \"date\" => \"Date & Time Translations\", \"64\" => \"Numerical label\", \"mixed_character_label2\" => \"a label with mixed characters: this text also contains a (, ) and a .\", ), // UPDATE 27TH JULY 2013 \"button\" => array( \"1\" => \"Add\", \"2\" => \"Edit\", \"3\" => \"Delete\", \"text_label\" => \"My string\", ),", "Global") set(#B, $list item($list from text(#A, "),"), 0), "Global") set(#find, $find regular expression(#B, "(?<=\").*?(?=\",)"), "Global") 2 Quote Link to post Share on other sites
Anonym 53 Posted November 19, 2014 Author Report Share Posted November 19, 2014 It doesn't work, but I am grateful that you put some time and efforts into trying to help me. Thank you! Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted November 19, 2014 Report Share Posted November 19, 2014 hmmm... not sure what you want then. this is what I get and seams to be getting what I think it is you want. only thing missing is " and ", and that can be fixed easy can you give screenshot? I made it with 5.5.1 should work in 4 too Quote Link to post Share on other sites
Anonym 53 Posted November 23, 2014 Author Report Share Posted November 23, 2014 The goal is to be able to set a "keystring", e.g. "descriptions" and scrape every key-value pair inbetween "<keystring>" => array(" and ")," but ONLY those, not those key-value pair that follows after the closing "),". This is what it is doing with your code. So in the below case, for the keystring "descriptions", it should only extract: "button" => "Button Translations", "date" => "Date & Time Translations", "64" => "Numerical label", "mixed_character_label2" => "a label with mixed characters: this text also contains a (, ) and a .", The things it extracts now is: "button" => "Button Translations", "date" => "Date & Time Translations", "64" => "Numerical label", "mixed_character_label2" => "a label with mixed characters: this text also contains a (, ) and a .", "1" => "Add", "2" => "Edit", "3" => "Delete", "text_label" => "My string", ...which is not correct. --- Original code: "english" => array( "descriptions" => array( "button" => "Button Translations", "date" => "Date & Time Translations", "64" => "Numerical label", "mixed_character_label2" => "a label with mixed characters: this text also contains a (, ) and a .", ), // UPDATE 27TH JULY 2013 "button" => array( "1" => "Add", "2" => "Edit", "3" => "Delete", "text_label" => "My string", ), ) // my comment: end of the "english" array Sorry, my mother tongue is not English, so maybe I am expressing myself a bit odd. I hope you understand. Thank you for all your help so far! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.