Matching quoted text question...

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Matching quoted text question...

    I'm trying to place HTML Tags around the contents of Quoted material.

    I'm using the following PERL code:
    $TextBlockToConvert =~ s/"(.+?)"/"<FONT Color=BLUE>\1<\/Font>"/g;



    Below, is an example of problem text this code chokes on.

    Example Text: msgStop("", "Invalid date")


    1. The 1st set of Quotes have no contents and so it is
    simply ignored.

    2. The code then finds the next set of Quotes... which is ", "
    NOTE: These Quotes do not belong to the same pair.
    The HTML formatting code is applied to the comma.

    3. Finally, the last set of Quotes are ignored because the
    code thinks there is only a single last Quote left.


    In this example (above), I would like the find only the last pair of quotes
    and substitute its contents with the same text, plus the HTML formatting
    code.



    Any help would be certainly appreciated.
    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney



    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney


    Rodney Wise Guest

  2. Similar Questions and Discussions

    1. Can't display quoted text in input box
      <b>Problem</b>: a user places the following text in an textbox: 83-96 Ford Bronco II 2WD 2" Lift When I try to retrieve this text from the database...
    2. Text Matching
      Hi everyone. I am working with an Illustrator 9.0 drawing that was given to my, drawn by someone else. I'm just trying to do some updating to it....
    3. Matching text question..
      I'm having trouble matching only entire words. If I run a search against a large block of text for the word: or It will find 'or' in every...
    4. and/or matching question
      Hi, On a web form, I have two fields "US_State" and "Other_State". In my perl script I have.... &no_State unless $FORM{'US_State'}; How...
    5. Best way to get quoted text in mysql?
      It took me a lot of trial and error to get text from an HTML form into MySQL to account for quotation marks being entered. I came up with the...
  3. #2

    Default Re: Matching quoted text question...

    Rodney Wise wrote:
    >
    > I'm trying to place HTML Tags around the contents of Quoted material.
    >
    > I'm using the following PERL code:
    > $TextBlockToConvert =~ s/"(.+?)"/"<FONT Color=BLUE>\1<\/Font>"/g;
    >
    > Below, is an example of problem text this code chokes on.
    >
    > Example Text: msgStop("", "Invalid date")
    >
    > 1. The 1st set of Quotes have no contents and so it is
    > simply ignored.
    >
    > 2. The code then finds the next set of Quotes... which is ", "
    > NOTE: These Quotes do not belong to the same pair.
    > The HTML formatting code is applied to the comma.
    >
    > 3. Finally, the last set of Quotes are ignored because the
    > code thinks there is only a single last Quote left.
    >
    > In this example (above), I would like the find only the last pair of quotes
    > and substitute its contents with the same text, plus the HTML formatting
    > code.
    >
    > Any help would be certainly appreciated.

    $TextBlockToConvert =~ s/"([^"]*)"/length $1 ? '"<FONT Color=BLUE>\1<\/Font>"' : '""'/eg;



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

  4. #3

    Default Re: Matching quoted text question...


    John W. Krahn wrote:
    >
    > Rodney Wise wrote:
    >
    > >
    > > I'm trying to place HTML Tags around the contents of Quoted material.
    > >
    > > I'm using the following PERL code:
    > > $TextBlockToConvert =~ s/"(.+?)"/"<FONT Color=BLUE>\1<\/Font>"/g;
    > >
    > > Below, is an example of problem text this code chokes on.
    > >
    > > Example Text: msgStop("", "Invalid date")
    > >
    > > 1. The 1st set of Quotes have no contents and so it is
    > > simply ignored.
    > >
    > > 2. The code then finds the next set of Quotes... which is ", "
    > > NOTE: These Quotes do not belong to the same pair.
    > > The HTML formatting code is applied to the comma.
    > >
    > > 3. Finally, the last set of Quotes are ignored because the
    > > code thinks there is only a single last Quote left.
    > >
    > > In this example (above), I would like the find only the last pair of quotes
    > > and substitute its contents with the same text, plus the HTML formatting
    > > code.
    > >
    > > Any help would be certainly appreciated.
    >
    >
    > $TextBlockToConvert =~ s/"([^"]*)"/length $1 ? '"<FONT Color=BLUE>\1<\/Font>"' : '""'/eg;
    Hi John.

    Almost right! But the deprecated \1 in the replacement string won't
    work with the /e modifier: it needs to be $1. Although I'm sure you
    knew that.

    For a diversion, here's my submission

    $TextBlockToConvert =~ s{("[^"]*")} {
    qq($1 ? '<FONT Color="BLUE">$1<\/FONT>' : '$1')
    }eeg;

    Which also corrects the HTML requirement for quotes around the
    attribute values. Although, after all, the <FONT> tag itself is
    deprecated in favour of CSS anyway! Can't win 'em all :)

    Rob




    Rob Dixon Guest

  5. #4

    Default RE: Matching quoted text question...

    Hello all...

    I'm wanting to write a script that scans a file,
    ignoring all lines until it reaches a certain
    section, then processes all lines in that
    section that are not comments, until it reaches
    the end of that section.

    The section would be designated like this:

    ## Beging Processing ##

    ## End Processing ##

    So I open my file, and skip all lines until I
    see that first bit... Then do stuff until I
    see the last bit. Can someone help me out with
    this?

    Tony


    #!/usr/bin/perl -w

    use strict;

    open (FILE, "<myfile")
    or die "Could not open Template. ($!)";

    while ($line = <FILE>) {
    #skip until beginning....

    #End when "End Processing" is reached
    last if $line =~ "End Processing";

    #Process the lines in between
    next if $line =~ /^#/;
    #do stuff....
    }
    Anthony Akens Guest

  6. #5

    Default Re: Matching quoted text question...

    Rob Dixon wrote:
    >
    > John W. Krahn wrote:
    > >
    > > $TextBlockToConvert =~ s/"([^"]*)"/length $1 ? '"<FONT Color=BLUE>\1<\/Font>"' : '""'/eg;
    >
    > Almost right! But the deprecated \1 in the replacement string won't
    > work with the /e modifier: it needs to be $1. Although I'm sure you
    > knew that.
    Yes, but I didn't really look at the replacement string, I just
    copy/pasted in in there.

    :-)

    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139