<HTML>
<HEAD>
<TITLE>Re: [TxMt] Re: How can I add a sequencial number to this Find/Replace?</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Thanks Graham, that worked great but I am having one problem.  The first line of your formula gets placed into my first placeholder.<BR>
<BR>
Example: <PortalObj portalFlags="16" numOfRows="1" initialRow=$ seq 16 32><BR>
<BR>
<BR>
On 2/20/15 9:41 AM, "Graham P Heath" <<a href="graham.p.heath@gmail.com">graham.p.heath@gmail.com</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT SIZE="2"><FONT FACE="Helvetica, Verdana, Arial"><SPAN STYLE='font-size:10pt'>You can combine Multiple Carets and Copy + Paste to achieve this easily.<BR>
<BR>
Find a list of the numbers you want to use, I assume you’re capable of generating the list in some way, but I like using the `seq` command in the terminal such as:<BR>
<BR>
</SPAN></FONT></FONT><BLOCKQUOTE><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT FACE="Courier New">$ seq 16 32<BR>
16<BR>
17<BR>
</FONT><FONT FACE="Helvetica, Verdana, Arial">[…snip...]<BR>
</FONT><FONT FACE="Courier New">31<BR>
32<BR>
</FONT></SPAN></FONT></BLOCKQUOTE><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT FACE="Helvetica, Verdana, Arial"><BR>
Note: It is important that they be separated by new line characters.<BR>
<BR>
Copy this list.<BR>
<BR>
Select your first placeholder: “##"<BR>
<BR>
</FONT><FONT FACE="Courier, Courier New">  <PortalOBj portalFlags="16" numbOfRows="1" initialRow=“<FONT COLOR="#009051">##</FONT>”><BR>
</FONT><FONT FACE="Helvetica, Verdana, Arial"><BR>
Press Control + W, this selects the next placeholder. Repeat until your selection contains all of your placeholders.<BR>
<BR>
Paste.<BR>
<BR>
Graham P Heath<BR>
<BR>
 <BR>
<BR>
On February 20, 2015 at 8:29:30 AM, René Schwaiger (<a href="sanssecours@f-m.fm">sanssecours@f-m.fm</a>) wrote:<BR>
 <BR>
</FONT></SPAN></FONT><BLOCKQUOTE><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT FACE="Helvetica, Verdana, Arial">Hi jgaltUSA, <BR>
<BR>
> On 20 Feb 2015, at 9:50 , jgaltUSA <<a href="jgaltUSA@gmail.com">jgaltUSA@gmail.com</a>> wrote: <BR>
>  <BR>
> I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.  <BR>
>  <BR>
> Here is my current replacement string: $1##$2  <BR>
>  <BR>
> How can I replace the ## with a sequential number?  <BR>
<BR>
I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want: <BR>
<BR>
    #!/usr/bin/env python <BR>
<BR>
    from re import compile <BR>
    from sys import stdin, stdout <BR>
<BR>
    regex = compile( <BR>
        """(<PortalOBj portalFlags="16" numbOfRows="1" initialRow=")\d+(">)""") <BR>
    index = 16 <BR>
<BR>
    def create_subtitute_function(): <BR>
        def substitute(match): <BR>
            global index <BR>
            replacement = "{}{}{}".format(match.group(1), index, match.group(2)) <BR>
            index += 1 <BR>
            return replacement <BR>
<BR>
        return substitute <BR>
<BR>
    text = regex.sub(create_subtitute_function(), stdin.read()) <BR>
    stdout.write(text) <BR>
<BR>
I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :). <BR>
<BR>
> For example, I want the first sequential number to be 16.  <BR>
>  <BR>
> Here is a screen capture:   <BR>
>  <BR>
> Thanks! <BR>
<BR>
Kind regards, <BR>
  René <BR>
<BR>
P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture. <BR>
<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="100%"><BR>
_______________________________________________ <BR>
textmate mailing list <BR>
<a href="textmate@lists.macromates.com">textmate@lists.macromates.com</a> <BR>
<a href="http://lists.macromates.com/listinfo/textmate">http://lists.macromates.com/listinfo/textmate</a><BR>
</FONT></SPAN></FONT></BLOCKQUOTE><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT FACE="Helvetica, Verdana, Arial"><BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></FONT></SPAN></FONT><FONT SIZE="1"><FONT FACE="Andale Mono"><SPAN STYLE='font-size:9pt'><BR>
_______________________________________________<BR>
textmate mailing list<BR>
<a href="textmate@lists.macromates.com">textmate@lists.macromates.com</a><BR>
<a href="http://lists.macromates.com/listinfo/textmate">http://lists.macromates.com/listinfo/textmate</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE>
</BODY>
</HTML>