chromedome has asked for the wisdom of the Perl Monks concerning the following question:

I am using a version of perl that is bundled into another application so I can not install any perl modules, I must use the standard out of the box perl that comes with my application.

The data I am working with is very strange (see below snippet). What I basically need to do is parse my data and look for any class= that does not have quotation marks and add them. Some class= have them and some don't. See below.

$string = qq( <LI>Donnez au client les renseignements sur le service  +RVI de façon qu'il soit prêt au moment de demander les formulaires fiscaux.  La +page Détails du système STAR contient maintenant les renseignements relatifs au système&nb +sp;RVI à l'intention des clients.</LI></OL> <TABLE class="interaction mceItemTable" border=0> <TBODY> <TR class=interaction_header> <TH colSpan=2>Interaction</TH></TR> <TR class=interaction_tr_even> <TD class=interaction_col1 width=80>Catégorie</TD> <TD>Year-End (Fin d'année)</TD></TR> <TR class=interaction_tr_odd> );

So class="interaction mceItemTable" would remain unchaged but stuff like class=interaction_header> and class=interaction_col1 width=80>Catégorie</TD> would look like class="interaction_header"> and class="interaction_col1" width=80>Catégorie</TD>

Any help is greatly appreciated.

Replies are listed 'Best First'.
Re: Strange regex needed
by choroba (Cardinal) on Nov 19, 2014 at 23:21 UTC
    It seems the class could end in a space or ampersand:
    $string =~ s/class=([^" &]+)/class="$1"/g;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thank you. I just now realized that it's not just the class= but all elements (border, width, colspan) have the possibility of not having quotes around them. Guess I will go back to the drawing board. Thanks again.
        $string =~ s/\b(class|border|width|colspan)=([^" &]+)/$1="$2"/g;
        Perl is the programming world's equivalent of English
Re: Strange regex needed
by MidLifeXis (Monsignor) on Nov 20, 2014 at 14:05 UTC

    It might also be appropriate to check if your presupposition is correct: do you need to use this version of perl, or can you install your own to use for your application?

    --MidLifeXis