[TxMt] Re: How can I add a sequencial number to this Find/Replace?

jgalt jgaltusa at gmail.com
Fri Feb 20 20:57:34 UTC 2015


Sorry, my previous example file was not formatted properly and it got
truncated. Here is a revised example file as XML: http://goo.gl/el0QMT


On 2/20/15 2:45 PM, "jgalt" <jgaltusa at gmail.com> wrote:

> Thanks for taking the time to create the bundle for me René.
> 
> I have installed it but I am not 100% sure how to use it.
> 
> I have entered the shortcut key command “^⌥⌘R” and it appears to run but I
> do not understand how to target the parts that I want to replace.
> 
> Here is a screen capture of my find and replace settings:
> http://goo.gl/YBqYy9
> 
> Here is a zipped file of the file that I am trying to edit:
> http://goo.gl/XOkDRh
> 
> I don't know if it matters...but the content that I am trying to edit is
> from a FileMaker clipboard. I believe that it is in XML format. The items
> that I am trying to edit are references to layout elements. (More
> specifically, references to FileMaker Portals.)
> 
> Thanks again for your help!
> 
> 
> On 2/20/15 8:26 AM, "René Schwaiger" <sanssecours at f-m.fm> wrote:
> 
>> Hi jgaltUSA,
>> 
>>> On 20 Feb 2015, at 9:50 , jgaltUSA <jgaltUSA at gmail.com> wrote:
>>> 
>>> 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.
>>> 
>>> Here is my current replacement string: $1##$2
>>> 
>>> How can I replace the ## with a sequential number?
>> 
>> 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:
>> 
>>     #!/usr/bin/env python
>> 
>>     from re import compile
>>     from sys import stdin, stdout
>> 
>>     regex = compile(
>>         """(<PortalOBj portalFlags="16" numbOfRows="1"
>> initialRow=")\d+(">)""")
>>     index = 16
>> 
>>     def create_subtitute_function():
>>         def substitute(match):
>>             global index
>>             replacement = "{}{}{}".format(match.group(1), index,
>> match.group(2))
>>             index += 1
>>             return replacement
>> 
>>         return substitute
>> 
>>     text = regex.sub(create_subtitute_function(), stdin.read())
>>     stdout.write(text)
>> 
>> 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 :).
>> 
>>> For example, I want the first sequential number to be 16.
>>> 
>>> Here is a screen capture:
>>> 
>>> Thanks!
>> 
>> Kind regards,
>>   René
>> 
>> 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.
>> 
>>>> 
>> _______________________________________________
>> textmate mailing list
>> textmate at lists.macromates.com
>> http://lists.macromates.com/listinfo/textmate
> 
> 




More information about the textmate mailing list