Showing posts with label regex. Show all posts
Showing posts with label regex. Show all posts

Monday, September 22, 2008

massive regex to convert comma delimited file to xml of known dtd

"([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%]"([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)","([a-zA-Z0-9 —\-;\!\?:\./&,$\(\)’<>'@–“”’#%\*]*)"

"$1","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$19","$20","$21","$22","$23","$24","$25","$26","$27","$28"

<event>
<event_id>$1</event_id>
<title1>$2</title1>
<discipline>$3</discipline>
<parent_teacher>$4</parent_teacher>
<start_date>$5</start_date>
<end_date>$6</end_date>
<date_label>$7</date_label>
<org_id>$8</org_id>
<org_name>$9</org_name>
<description>$10</description>
<grade_level>$11</grade_level>
<prog_type>$12</prog_type>
<hours>$13</hours>
<length>$14</length>
<max_group_size>$15</max_group_size>
<res_lead_time>$16</res_lead_time>
<fees>$17</fees>
<contact>$18</contact>
<languages>$19</languages>
<free_p>$20</free_p>
<show_p>$21</show_p>
<writeup_p>$22</writeup_p>
<featured_p>$23</featured_p>
<comments>$24</comments>
<creation_date>$25</creation_date>
<creation_user>$26</creation_user>
<edit_date>$27</edit_date>
<edit_user>$28</edit_user>
</event>

Get rid of everything but what is in between two tags

<name>blah</name>

leaves behind <name>blah >

(it's not perfect but it will help you widdle down large xml files to just the nodes you want!)

((?!<name>.*</name>|Name>.*</name>|ame>.*|me>.*|e>.*|>.*|.*).)*

find and replace recursively in all files

find ./httpdocs/template-modules/ -type f -exec sed -i 's/beta.refinery29.com/ww2.refinery29.com\//g' {} \;

here is one to replace directory paths:

find ./httpdocs/templates/ -type f -exec sed -i 's/\/var\/www\/vhosts\/refinery29.com\/subdomains\/beta\/httpdocs\//\/var\/www\/vhosts\/refinery29.com\/httpdocs\//g' {} \;