Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [Robert] Regex for dl/dt/dd or table

Quote Reply
Re: [Robert] Regex for dl/dt/dd or table In reply to
You could try something like this:

Code:
#!perl

use CGI;
use strict;

my $test = q|sdfsdfsdfsdf
[t]
Monday: 12-14
Tueday: 12-18
Wednesday: 12-18
[/t]
dsfsdfsdfsd
fsdfsdfsdf
|;

$test =~ s{\[t\](.*)\[\/t\]}{do_table($1)}segm;

print "Now: $test\n";

sub do_table {

my @vals;
foreach (split /\n/, $_[0]) {
chomp;
next if length $_ < 1;
my ($day,$times) = split /:/, $_;
push @vals, qq|
<tr>
<td>$day</td>
<td>$times</td>
</tr>\n|
}

return qq|<table>| . join("",@vals) . qq|</table>|;
}

=cut
<table>
<tr>
<td>Monday</td>
<td>12-14</td>
</tr>
</table>
=cut

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread Regex for dl/dt/dd or table Robert 7453 Dec 4, 2017, 8:34 AM
Thread Re: [Robert] Regex for dl/dt/dd or table
Andy 7349 Dec 5, 2017, 12:23 AM
Thread Re: [Andy] Regex for dl/dt/dd or table
Robert 7339 Dec 5, 2017, 3:00 AM
Thread Re: [Robert] Regex for dl/dt/dd or table
Andy 7336 Dec 5, 2017, 4:15 AM
Thread Re: [Andy] Regex for dl/dt/dd or table
Robert 7334 Dec 5, 2017, 6:11 AM
Thread Re: [Robert] Regex for dl/dt/dd or table
Andy 7329 Dec 5, 2017, 7:03 AM
Thread Re: [Andy] Regex for dl/dt/dd or table
Robert 7318 Dec 5, 2017, 2:35 PM
Thread Re: [Robert] Regex for dl/dt/dd or table
Andy 7304 Dec 5, 2017, 11:58 PM
Thread Re: [Andy] Regex for dl/dt/dd or table
Robert 7250 Dec 7, 2017, 4:19 AM
Thread Re: [Robert] Regex for dl/dt/dd or table
Andy 7238 Dec 7, 2017, 10:45 AM
Thread Re: [Andy] Regex for dl/dt/dd or table
Robert 7239 Dec 7, 2017, 11:14 AM
Post Re: [Robert] Regex for dl/dt/dd or table
Robert 7222 Dec 7, 2017, 12:21 PM