replace blocks of words starting and ending with x and y

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

jesuslives
Posts: 7
Joined: Wed Apr 16, 2008 12:40 pm

replace blocks of words starting and ending with x and y

Post by jesuslives »

I am trying to do a Replace All. I need to remove all sections with certain words.

Starting word is START (a bunch of words which vary) and ending word is END
Example:
1234 START more words END 123
1234 START xyz END 123
textpad is fun START abc END la la la
gan

Post by gan »

I'm not sure if i understand what you want to replace/remove, but with a further explanation it would be easier to give you an exact example.

But if you want to remove/replace everything between START and END including START/END you could search for "START.+END ?" (there is a space before ?) and replace with something or nothing. If you want to keep START/END, but remove everything between them you could search for "(START).+(END)" and replace with "\1 \2". That will keep START and END with a space between them. The quotation marks should not be included in the search string.
There are other ways as well and maybe a better way to do this, but then some more info would be nice to know exactly what you want. Regular expression must be checked of course.
Last edited by gan on Wed Apr 16, 2008 1:54 pm, edited 2 times in total.
jesuslives
Posts: 7
Joined: Wed Apr 16, 2008 12:40 pm

didn't work

Post by jesuslives »

Gan,
That doesn't work. You understand correctly what I am trying to do. I am trying to remove everything including start & end.

I am typing in the "Find What" box: START.+END

The error says "cannot find regular expression.

Thanks,

Kevin
gan

Post by gan »

I just edited my post with a few changes so you could read it once more, but are you sure the cursor is located correctly? If the cursor is at the end of the file and you do a seach "Down" there will be no hits and the same if at the beginning and search "Up". Also make sure you don't have Match case checked unless what you search for have the same case. I also have "POSIX regular expression syntax" enabled, but that shouldn't matter. It works fine for me using Textpad 5.2 and the 3 lines you gave as an example.
jesuslives
Posts: 7
Joined: Wed Apr 16, 2008 12:40 pm

still doesn't work

Post by jesuslives »

START.+END ? (no quotes) Searching up or down will not find regular expression.

-Kevin
David Haslam
Posts: 24
Joined: Wed Oct 01, 2003 2:24 pm
Location: United Kingdom
Contact:

This works for your example

Post by David Haslam »

This works for your example:

Code: Select all

START.*END

Code: Select all

1234 START more words END 123 
1234 START xyz END 123 
textpad is fun START abc END la la la
became

Code: Select all

1234  123 
1234  123 
textpad is fun  la la la
You could easily follow it with find two spaces and replace by a single space.
Best regards,

David F Haslam, MA, CEng, MIEE
gan

Post by gan »

What version of textpad do you use?
Does any regular expression work? Like a search for "." (should match all characters) or a search for "^.+" or "^.*" (should match all lines).
This is pretty basic usage of regular expression and don't understand why it doesn't work. I assume searching without regular expression work fine.
David Haslam
Posts: 24
Joined: Wed Oct 01, 2003 2:24 pm
Location: United Kingdom
Contact:

Version

Post by David Haslam »

I am using v4.7.3 and have no plan to upgrade to version 5.2
Best regards,

David F Haslam, MA, CEng, MIEE
gan

Re: This works for your example

Post by gan »

David Haslam wrote:This works for your example:

Code: Select all

START.*END

Code: Select all

1234 START more words END 123 
1234 START xyz END 123 
textpad is fun START abc END la la la
became

Code: Select all

1234  123 
1234  123 
textpad is fun  la la la
You could easily follow it with find two spaces and replace by a single space.
Search for

Code: Select all

START.*END ?
will remove one space as well so there is no need to search and replace twice. Anyway + instead of a * should work as well so your example should do the same as mine. Unless the + does not work with TP 4.....cannot remember since it's a long time since i used 4.x.
Last edited by gan on Wed Apr 16, 2008 2:53 pm, edited 1 time in total.
David Haslam
Posts: 24
Joined: Wed Oct 01, 2003 2:24 pm
Location: United Kingdom
Contact:

I agree that using star plus gave the same bug

Post by David Haslam »

I agree.

Code: Select all

START.+END
gave same symptoms even in TP 4.7.3
Best regards,

David F Haslam, MA, CEng, MIEE
gan

Re: I agree that using star plus gave the same bug

Post by gan »

David Haslam wrote:I agree.

Code: Select all

START.+END
gave same symptoms even in TP 4.7.3
So you got it working using TP 4.7.3? Do you have any tips why it doesn't work for jesuslives? I cannot think of any reason why it's working for you and me, but not jesuslives.
jesuslives
Posts: 7
Joined: Wed Apr 16, 2008 12:40 pm

duh....

Post by jesuslives »

I think I just upgraded unecessarily.

My end string is \fs28. I can key off of s28 but it seems to have a problem going across multiple lines. It works fine as long as they are on the same line.

The real END string is preceded by a backslash.
START CREATIONTIME='2002-10-10T16:13:46' LASTMODIFIEDTIME='2002-11-29T17:27\f5\fs28\cf0\b\protect
gan

Re: duh....

Post by gan »

jesuslives wrote:I think I just upgraded unecessarily.
My end string is \fs28. I can key off of s28 but it seems to have a problem going across multiple lines. It works fine as long as they are on the same line.
The real END string is preceded by a backslash.
START CREATIONTIME='2002-10-10T16:13:46' LASTMODIFIEDTIME='2002-11-29T17:27\f5\fs28\cf0\b\protect
Well then i understand why it wasn't working. Your first example (the 3 lines) isn't even close to the real data since the end string is different, there is no spaces and it might go across more then a single line. With regular expressions it's important to get a accurate example to be able to give you a working search pattern.

Could you provide a more accurate example with a few lines where you also include an example that goes across more then one line? Then it could be possible to give you a working search pattern. Does it ever cross more then two lines? Is START always at the beginning of the line?

Using regular expression searching for a double backslash "\" will match a single backslash "".
jesuslives
Posts: 7
Joined: Wed Apr 16, 2008 12:40 pm

real sample

Post by jesuslives »

OK, sorry about that. Here is the exact text:
I need to remove all of this text and place a carriage return after fs28.
-Thanks
CREATIONTIME='2002-10-10T16:13:46' LASTMODIFIEDTIME='2002-11-29T17:27:05' SCOPE='<FormScope><Modality>CR</Modality><BodyPart>CSPINE</BodyPart><BodyPart>SPINE</BodyPart></FormScope>'
TEXTFORMAT='4' TEXT='{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fswiss Arial;}{\f3\froman Times New Roman;}{\f4\fswiss\fprq2 System;}{\f5\froman\fprq2 Times New Roman;}}
{\colortbl\red0\green0\blue0;\red255\green255\blue255;}
\deflang1033\pard\ri140\plain\f5\fs28\cf0
jesuslives
Posts: 7
Joined: Wed Apr 16, 2008 12:40 pm

....more

Post by jesuslives »

I just saw the rest of your questions.

No, the first word to remove is almost never at the start of the line.

-Kevin
Post Reply