On May 20, 2013, at 05:53, Dom O'Brien <[email protected]> wrote:
> I'm trying to work out a search and replace syntax to the following numbers:
______________________________________________________________________

Hey Dom,

That's not really a job for find/replace since some calculations are required.

Maarten and JD have given a couple of example Text Filters which should be 
saved here:

~/Library/Application Support/BBEdit/Text Filters/

The following scripts will work with your single line of data or something like 
this:

-------------------------------------------------------------------------------------------

1,4
Some embedded text.
10,20

20,2

-------------------------------------------------------------------------------------------

This script produces the same output as Maarten's using Perl instead of Python.

-------------------------------------------------------------------------------------------

#! /usr/bin/env perl
   use v5.010; use strict; use warnings;
while (<>) {
   if ( m!(\d+),(\d+)! ) {
      foreach ( 1..$2 ){
         say "$1_$_";
      }
   }  else {
        print;
      }
}

-------------------------------------------------------------------------------------------

But perhaps you want to increment from the value of the left-hand number to 
that of the right-hand number rather than starting the index at 1.

This one only handles positive incrementing.

-------------------------------------------------------------------------------------------

#! /usr/bin/env perl
   use v5.010; use strict; use warnings;
while (<>) {
   if ( m!(\d+),(\d+)! ) {
      if ( $1 > $2 ) { die "Error: value 2 ($2) > value 1 ($1)!\n      " };
      foreach ( $1..$2 ){
         say "$1_$_";
      }
   }  else {
         print;
      }
}

-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. 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>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].


Reply via email to