On Mon, May 21, 2012 at 05:41:50AM -0700, RobS wrote: > On Wednesday, 11 April 2012 22:25:26 UTC-3, Ronald J Kimball wrote: > > > > If you'd rather insert the numbers into the HTML, you would need a script > > of some kind. Here's a simple one in Perl, which also replaces existing > > numbering, if any: > > > > #!perl -p > > s/(<dt[^>]*>)(\d+\. )?/$1 . ++$i . ". "/ige; > > > > I have a similar problem but have no experienece with PERL, so I'm finding > it difficult to modify this bit of code to suit. In my case I have a series > of lines like this... > > <..the start of an href here..>[+]</a> > <..the start of an href here..>[+]</a> > > ... and I want to replace each of the plus signs with a sequential number, > starting with 1, so they end up like this... > > <..the start of an href here..>[1]</a> > <..the start of an href here..>[2]</a> > > There are about 40 altogether, so more than one digit is required for most > of them. With only 40 I could, of course, do it manually, but I'd learn > nothing from that. How would PERL handle this?
Here's how the substitution might be modified for your use case: #!perl -p s,(<a\s[^>]+>\[)(?:\+|\d+)(\]</a>),$1 . ++$i . $2,ige; The regex now has three parts: (<a\s[^>]+>\[) matches the opening A tag and the left square bracket. (?:\+|\d+) matches either a plus sign or some digits, to replace existing numbering as well. (\]</a>) matches the right square bracket and the closing A tag. The replacement combines the two captured parts with the value of an incremented variable. Ronald -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
