J
John
I have text that might have had a star character in the proprietary
orginating system. The character is used in ratings boxes: A three-
star movie, a four-star restaurant, etc.
By the time it's exported and available to me, it's represented by a
string: "<star>".
I want to suround consecutive stars with font coding and replace each
instance of the string with a single character that, in conjuction
with the font change, will eventually print as a star.
To set up this substitution, I change the strings back to a unique
character, one that I reckon would never occur in nature.
When I try to surround any repetitions of this invented character, I
instead match everything.
===
#!/usr/bin/perl -w
use strict;
my $text = "Cuisine: Urban deli<ep>";
$text .= "Overall: <star><star><star><star><1/2> (very good to
excellent)<ep>";
$text .= "Food: <star><star><star><star><1/2><ep>";
$text =~ s/\<star\>/_STAR_/ig; # uscores easier in regex than angle
brackets.
$text =~ s/_STAR_/\xbc/g; # change pseudocharacter to single
character
$text =~ s/(\xbc*)/_STARFONT_$1_ENDSTAR/g; #bracket groups in more
pseudocode
print $text;
====
If I limit the search to five consecutive stars, the match works as I
intended:
===
#!/usr/bin/perl -w
use strict;
my $text = "Cuisine: Urban deli<ep>";
$text .= "Overall: <star><star><star><star><1/2> (very good to
excellent)<ep>";
$text .= "Food: <star><star><star><star><1/2><ep>";
$text =~ s/\<star\>/_STAR_/ig; # uscores easier in regex than angle
brackets.
$text =~ s/_STAR_/\xbc/g; # change pseudocharacter to single
character
$text =~ s/(\xbc{1,5})/_STARFONT_$1_ENDSTAR/g; #bracket groups of
stars in more pseudocode
print $text;
===
So what am I missing when it comes to the first search?
Certainly, I am missing some superior technique for matching repeated
instances of such a string, so I am open to suggestions there.
John Campbell
Haddonfield, NJ 08033
orginating system. The character is used in ratings boxes: A three-
star movie, a four-star restaurant, etc.
By the time it's exported and available to me, it's represented by a
string: "<star>".
I want to suround consecutive stars with font coding and replace each
instance of the string with a single character that, in conjuction
with the font change, will eventually print as a star.
To set up this substitution, I change the strings back to a unique
character, one that I reckon would never occur in nature.
When I try to surround any repetitions of this invented character, I
instead match everything.
===
#!/usr/bin/perl -w
use strict;
my $text = "Cuisine: Urban deli<ep>";
$text .= "Overall: <star><star><star><star><1/2> (very good to
excellent)<ep>";
$text .= "Food: <star><star><star><star><1/2><ep>";
$text =~ s/\<star\>/_STAR_/ig; # uscores easier in regex than angle
brackets.
$text =~ s/_STAR_/\xbc/g; # change pseudocharacter to single
character
$text =~ s/(\xbc*)/_STARFONT_$1_ENDSTAR/g; #bracket groups in more
pseudocode
print $text;
====
If I limit the search to five consecutive stars, the match works as I
intended:
===
#!/usr/bin/perl -w
use strict;
my $text = "Cuisine: Urban deli<ep>";
$text .= "Overall: <star><star><star><star><1/2> (very good to
excellent)<ep>";
$text .= "Food: <star><star><star><star><1/2><ep>";
$text =~ s/\<star\>/_STAR_/ig; # uscores easier in regex than angle
brackets.
$text =~ s/_STAR_/\xbc/g; # change pseudocharacter to single
character
$text =~ s/(\xbc{1,5})/_STARFONT_$1_ENDSTAR/g; #bracket groups of
stars in more pseudocode
print $text;
===
So what am I missing when it comes to the first search?
Certainly, I am missing some superior technique for matching repeated
instances of such a string, so I am open to suggestions there.
John Campbell
Haddonfield, NJ 08033