Home: Perl Programming Help: Regular Expressions:
Matching and Replacing : in line



lapsan
Deleted

Aug 11, 2000, 8:39 AM


Views: 5708
Matching and Replacing : in line

<p>Hello.

<p>I have the following:

<pre> if ($filename =~ m/^{5,}[A-Z]./) {
$section_title = ($filename =~ s/[:]?/':</B>\n<BR><BR>'/);
$filename = "";
}
</pre>

<p>And it doesn't work. I want it to replace the colon it finds on lines
that have the first five characters written in CAPS and replace it with
the colon as well as some HTML.

<p>I've also tried this:

<pre> if ($filename =~ m/^{5,}[A-Z]./) {
$section_title = ($filename =~ s/?[:]./':</B>\n<BR><B>\n'/);
$filename = "";
}
</pre>

<p>That doesn't work either.

<p>I'm new to regular expressions have been searching for some helpful
information on this problem all over the place. Even went so far as to
try to use the Reg. Expression used in the Perl Cookbook for parsing
text files by comma seperated data.

<p>Anyone have any suggestions?

Thanks


dws
Deleted

Aug 11, 2000, 9:35 AM


Views: 5708
Re: Matching and Replacing : in line

The way to match at least 5 capital letters at the beginning of a string is:

/^[A-Z]{5,}/