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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: pattern matching with specified length
by Zaxo (Archbishop) on Jun 05, 2006 at 15:38 UTC

    I think you want a character class which excludes the ones you don't want, with a quantifier.

    my $allowed = qr/^[^<>"&]{8,12}$/;
    The end anchors enforce length and exclusion of the forbidden characters.

    You mention XML. There are lots of CPAN modules dealing with XML. One of them may help with the larger picture of whatever you're trying to do.

    After Compline,
    Zaxo

Re: pattern matching with specified length
by planetscape (Chancellor) on Jun 05, 2006 at 15:37 UTC

    Please see: this

    HTH

    planetscape
Re: pattern matching with specified length
by dsheroh (Monsignor) on Jun 05, 2006 at 15:40 UTC
    I'd do it with an allow list and substitution:
    $my_var =~ s/[^a-zA-Z0-9_@#$%]//g; print "Bad length!" unless (length $my_var >= 8) && (length $my_var <= + 12);
    This will remove all illegal characters, then complain if what's left is outside of the desired size range.
Re: pattern matching with specified length
by GrandFather (Saint) on Jun 05, 2006 at 21:08 UTC

    I've read your question several times and still do not understand what you want to achieve. Perhaps you should show us the code that you are having trouble with and a small sample of the data. Show us the output you get and what you expected. Something of this nature should only require half a dozen lines of code and less than fifty characters of data to show the problem.

    As the good Zaxo implies, XML and regex in one question is a triger here and we generally strongly suggest you use one of the many modules that know how to handle XML. A favourite is XML::Twig.


    DWIM is Perl's answer to Gödel