Welcome to WebmasterWorld Guest from 54.144.48.252

Forum Moderators: open

Message Too Old, No Replies

NoteTab Pro (or regex text editor) to find code sections to replace

analogous to Library Items in DreamWeaver... is it possible?

     
6:35 pm on Apr 15, 2007 (gmt 0)

WebmasterWorld Administrator robert_charlton is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I'd like to be able to set up NoteTab Pro to do global search and replacement of sections of code in a group of documents. The sections would be identified by unique starting and ending text strings, but what's in between might vary. This would allow global replacement of sections, but wouldn't be broken by manual change in specific documents. (I understand that these manual changes would be lost in the replacements). Is it possible?

I haven't gotten into either regular expressions or Clip Programming with NTP, but I'm thinking I'd have to use one or the other to accomplish this, if it can be done.

My approach will be to identify a starting string and an ending string, and set up a routine to globally search and replace these and everything in between them. If doable, this would effectively work like the Library Items in DreamWeaver, I'm thinking, and be useful for maintaining global page sections like nav menus.

I'm not really a programmer, but could probably tackle this with a code outline and indications of what syntax I need to learn.

Anyone done this? If Clip Programming is required, this is NTP specific. If regular expressions will suffice, then experience with any text editor supporting regex would probably apply. Thoughts?

5:52 am on Apr 24, 2007 (gmt 0)

WebmasterWorld Administrator robert_charlton is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Anyone?

Let me simplify the question....

Is there a way of using regex in a text search to identify two text strings, one at the beginning of a section and one at the end, and let me replace everything in between?

6:09 am on Apr 24, 2007 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



More or less... with Perl type regular expressions you need to identify the text to change, and then change it.

An approximate syntax is:

/start text here .+? end text here/

You would need to escape special characters in the 'start text here' and 'end text here' sections.

. means anything, + means one or more of the previous, and the? modifies the + so that it goes for the shortest of possible solutions. All in all, it will look for the shortest string between 'start text here' and 'end text here'.

Altogether:
Search for: /start text here .+? end text here/
Replace with: something else....

Note that this removes 'start text here' and 'end text here'. If you want to keep them, either stick them in brackets in the search regex and access them in the replacement string with $1 and $2 (or similar) or just retype them in the replacement string.

8:48 am on Apr 24, 2007 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



sounds like a job for awk but my awk skills are too rusty to help beyond that suggestion.
being lazy, i would naturally write something in perl these days...
6:45 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Administrator robert_charlton is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



...with Perl type regular expressions...

vvv - I'm not a programmer, but I can follow syntax if I'm pointed to it. Question is whether what you're suggesting can just be entered into the search field, or whether I need to run Perl or some such within my text editor (I ask this sloppily, because I really don't know what's involved).

Way back when I used MS Word for DOS as a text editor, I was able to use its macro and scripting language (which were very easy to use) to do a lot of search and replace routines... even to find strings, move them, and change case.

But here I was just hoping for something very simple... basically something that I could enter into the search and replace fields, maybe with something like regex which I understand NoteTab Pro supports.

NoteTab Pro also has a Clip scripting language that I haven't used. The documentation assumes more of a background in programming than I have.

5:00 am on May 7, 2007 (gmt 0)

WebmasterWorld Administrator robert_charlton is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



More or less... with Perl type regular expressions you need to identify the text to change, and then change it.

An approximate syntax is:

/start text here .+? end text here/

vvv - Finally have come to understand what you were talking about... ie, you're talking about the particular regular expressions syntax, not about using Perl itself.

When I said I'm not a programmer, I really meant it. ;)

Thanks.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month