On 20 mei 2013, at 12:53, Dom O'Brien <[email protected]> wrote:

> Hello - I'm trying to work out a search and replace syntax to the following 
> numbers:
> 
> 1,4
> 
> I want to add a "_" to the first number ("1_") and repeat to the value of the 
> next number. so 1,4 would end up being
> 
> 1_1
> 1_2
> 1_3
> 1_4
> 
> I can't work out the syntax - can anyone help??

Can't be done with a regular expression search & replace. BBEdit can help 
though, with a custom filter. The specification is somewhat incomplete, but the 
following python script should help (note that whitespace is significant in 
Python). Save in the 'Text Filters' directory in the BBEdit directory in the 
application support directory within your Library (hidden) folder. 

#!/usr/bin/env python

import sys
import re

pat = re.compile('^(\d+),(\d+)(.*)$')

for line in sys.stdin:
    line = line.rstrip() # remove trailing newline (and other whitespace)
    m = pat.match(line)
    if m:
        for i in xrange(1,int(m.group(2))+1):
            sys.stdout.write("{0}_{1}{2}\n".format(m.group(1), i, m.group(3)))
    else:
        sys.stdout.write("{0}\n".format(line))


-- 
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