Is it possible to loop over multiple lines of text with RegEx and wrap each line in some contextual HTML? -
I'm comfortable using RegEx in a slightly javascript app / plugins, but right now I want Regx to save me. Too many times by doing the following:
I have a long text file that is formatted in the following way:
area in which the space may contain the address that is empty Location and special character phone number (empty line) area ... (like above Repeats composition) Here is a brief excerpt:
Ponsonby 114 Ponsonby Rd open til 3 AM Friday amp; Saturday 09 3786466 Queen St. 291 Queen St. (next to Bore Dares) 09 3090660 Sylvia Park Sylvia Park Shopping Complex (286 Mount Wellington Highway) 09 5730100 I know that it is wrapped in the bottom Required: & lt; Li class = "item" & gt; & Lt; P class = "phone" & gt; 09 3786466 & lt; / P & gt; & Lt; Div class = "location" & gt; & Lt; Strong> Ponsonby & lt; / Strong> & Lt; P class = "address" & gt; 114 Ponsonby Rd Open Till 3 AM Friday & amp; Saturday and lt; / P & gt; & Lt; / Div & gt; & Lt; / Li & gt; Can I run a regx to find information and loop for each line on my content wrapping items in such markups?
I do not have a systemmat \ N ([\ w \ s \ b.] +) \ N ([\ d] +) $ \ n \ n and then replace me with my
& lt; Li class = "item" & gt; & Lt; P class = "phone" & gt; $ 3 & lt; / P & gt; & Lt; Div class = "location" & gt; & Lt; Strong> $ 1 & lt; / Strong> & Lt; P & gt; $ 2 & lt; / P & gt; & Lt; / Div & gt; & Lt; / Li & gt; Any help would be appreciated.
Thanks for reading.
Jannis
This tested task should do the trick:
function process_data (text) {// html-ify some data var re = /(\S.*)\r?\n(\S.* ) \ R? \ N ([\ d \ -] +) (? = \ R? \ N [] * \ R \ \ N | \ s * $) / g; Var rep_str = "& lt; li class = \" item \ "& gt; \ n" + "& lt; p class = \" phone \ "& gt; $ 3 & lt; / p & gt; \ n" + "& Lt; div class = \" location \ "& gt; \ n" + "& lt; strong & gt; $ 1 & lt; / strong & gt; \ n" + "& lt; p & gt; 2 $ \ n "+" & lt; / div & gt; \ n "+" & lt; / li & gt; \ n "; Return text. Location (again, rep_str); }
Comments
Post a Comment