Find&Replace,Beginning&End of Text using Wild Card

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Find&Replace,Beginning&End of Text using Wild Card

Post by jmca2000 »

Hi, I tried finding an example of this on the forum but could not find it.

How do you Find the following using a wild card:

whiteLineDown
&& orangeLineUp
&& yellowLineDown
&& cyanLineDown
&& blackLineDown
&& dodBlueLineDown
&& blueLineDown
&& greenLineDown
&& redLineDown

AND Replace it with the following: :?:

Print("&& whiteLineDown");
Print("&& orangeLineUp");
Print("&& yellowLineDown");
Print("&& cyanLineDown");
Print("&& blackLineDown");
Print("&& dodBlueLineDown");
Print("&& blueLineDown");
Print("&& greenLineDown");
Print("&& redLineDown");

Thank You Very Much For Your Support in Advance. :D
Joe Cagg
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Does this supersede your earlier question? This one is much easier:

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Replace... (<F8>):
Find what: ^&* *(.+)
Replace with: Print("\&\& \1");

[X] Regular expression

Replace All
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Hi Ben, Thanks for your Help. I used the code you gave me but I got the Following response: "Cannot find regular expression:" ^&* *(.+) :(
I don't know why it did not work? I only used one space and that was between the * *. Also to answer your question, it did not supersede my other quesion. I also need to be able to Convert and Transpose Text to an Additional Location. Thanks Again for your support.
Joe Cagg
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Are you using "Posix" regular expression syntax?

Has a spurious space been introduced at the end of your regex?

Are there leading spaces in your source that aren't in your posting?
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Hi Ben, In my C# compiler it sort of works but does not work in TextPad :?: .
I get the Following result from the compiler:

Print("whiteLineDownwhiteLineDown whiteLineDown");
Print("&& orangeLineUp&& orangeLineUp orangeLineUp");
Print("&& yellowLineDown&& yellowLineDown yellowLineDown");
Print("&& cyanLineDown&& cyanLineDown cyanLineDown");
Print("&& blackLineDown&& blackLineDown blackLineDown");
Print("&& dodBlueLineDown&& dodBlueLineDown dodBlueLineDown");
Print("&& blueLineDown&& blueLineDown blueLineDown");
Print("&& greenLineDown&& greenLineDown greenLineDown");
Print("&& redLineDown&& redLineDown redLineDown");

:?: :?: :?:
Joe Cagg
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I can assure you it does work in TextPad.

What are the answers to the questions I asked?

I presume you mean it works as you describe in the IDE of your C# compiler. That is not relevant here: your IDE is not using TextPad's regex engine.
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Are you using "Posix" regular expression syntax?

I check the box that says Regular expression.

Has a spurious space been introduced at the end of your regex?

No.

Are there leading spaces in your source that aren't in your posting?

No, I Cleaned the code up took all spaces and tabs out.

Thanks.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Please read my original reply again and follow its suggestions precisely.
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Hi Ben,

Please forgive my lack of knowledge of Regular expressions, I NEVER heard of this until about 2 days ago. I wish I would have known about this weeks ago, I can't tell you the amount of time this would have saved me.

I guess I figured out what you meant by Use POSIX (what ever that means) :idea: . I went to Preferences > Editor >and checked the box that says "Use POSIX regular expression syntax". It WORKS, Thanks for your patience. :)

What would I replace in the code to Convert 'whiteLineDown' to 'Print("&& whiteLineDown"); ' , that is the only one that does not start with && :?:

Also Could you PLEASE, PLEASE help me with the other Post otherwise I'm going to have to make 1000's of manual changes to my code :?:

THANKs so Much in Advance. :D
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

My suggestion does convert
whiteLineDown
to
Print("&& whiteLineDown");

The regex is contructed in an odd way to ensure it does do this. It's a bit tricky with TextPad's weak and slightly perverse old regex engine.
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

I'm Sorry Ben I meant 'whiteLineDown' to 'Print("whiteLineDown");'

Thanks.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

That is not what you asked for originally.
Find what: .+
Replace with: Print("\0");

[X] Regular expression

Replace All
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

I Know, Thanks for your continued Help.

I Hope it's still possible you could help me out with the other modified Post?

Thanks Again Joe.
Post Reply