Regular Expression Help Please

General questions about using TextPad

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

Post Reply
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Regular Expression Help Please

Post by dforrest »

I have very many entries in a file similar to the following:
FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40082.s )
I need to change this to:
"FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40082.s )"
Each has a different five digit number ("40082" in this example) which should not be changed. Is there any way to do this with a regular expression?

To complicate this there is also the expressions similar to the following which should not be changed.
FileName ( ukfs3r_tl_20m_7d13.s )
Any help would be greatly appreciated.
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Is the string
FileName ( ... )
a whole line?

Do you want to enclose such lines in double quotes?

What distinguishes the strings that you want to do this to from those you do not want to do it to?
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Post by dforrest »

Yes the string is to be changed to be enclosed in double quotes.

All strings to be changed are identical except for the five digit number number which should remain unchanged.
User avatar
AmigoJack
Posts: 500
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Find:

Code: Select all

^(FileName \( \.\.\\\\\\\\\\\\\\\\\.\.\\\\\\\\\\\\\\\\routes\\\\\\\\\\\\\\\\Chiltern\\\\\\\\\\\\\\\\Dynatrax\\\\\\\\\\\\\\\\DynaTrax-[0-9]{5}\.s \))$
Replace with:

Code: Select all

"$1"
What have I done?
  • Escaping every character that has a meaning in regular expressions (round brackets, backslashes, dots) - ironically I did this using TextPad's "Replace" feature
  • Adding start of line and end of line -markers
  • 5 digit random number
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Post by dforrest »

This in in principle is what I need although there are two problems.

1. It is only the following string which I am attempting to enclose with double quotes. Your solution quotes the whole line.
..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s
2. There are two tab characters at the beginning of the line(before "FileName (.." which are not showing in the examples I am typing in the post. I have added -TAB-TAB- in the example below to show the position of them.
-TAB-TAB-FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s )
The following is a bigger extract of the code being adjusted:
TrackObj (
UiD ( 84 )
SectionIdx ( 40053 )
Elevation ( 0 )
CollideFlags ( 527 )
FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s )
StaticFlags ( 00200180 )
Position ( -697.444 45.4542 655.951 )
QDirection ( 0 0.393961 0 0.919127 )
VDbId ( 4294967294 )
StaticDetailLevel ( 0 )
)

This needs to be:
TrackObj (
UiD ( 84 )
SectionIdx ( 40053 )
Elevation ( 0 )
CollideFlags ( 527 )
FileName ( "..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s" )
StaticFlags ( 00200180 )
Position ( -697.444 45.4542 655.951 )
QDirection ( 0 0.393961 0 0.919127 )
VDbId ( 4294967294 )
StaticDetailLevel ( 0 )
)
Not showing is one tab character before the fist line and two tab characters before the other lines.
User avatar
AmigoJack
Posts: 500
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

dforrest wrote:Your solution quotes the whole line.
You answered 2 different questions about lines with "Yes", hence I assumed just that. Remove

Code: Select all

^
and

Code: Select all

$
dforrest wrote:There are two tab characters at the beginning of the line(before "FileName (.." which are not showing in the examples I am typing in the post.
That's because you always use
instead of

Code: Select all

 - the former is meant for text and citations, the latter for also keeping whitespaces (such as indents thru tabs).
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Post by dforrest »

Thank you Jack but I am confused. Where do we go from here?
User avatar
AmigoJack
Posts: 500
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

From my perspective I explained and referenced everything precisely, unambiguously, and completely. Maybe you can elaborate on why you are confused (at which point, and what did you understood so far) and what you expect if you still want to go on.

In other words: "confused" and "go from here" is too vague and as helpful to me as if I'd "help" you with a reply of "it's all in the text" - it surely is accurate, but doesn't improve understanding in any way.
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Post by dforrest »

Jack, I will state my initial query again and hope that this time I describe it correctly!

I have several lines in a file as the following two lines:

Code: Select all

		FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s )
and

Code: Select all

		FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40124.s )
The space showing at the beginning of the line (before "FileName") comprises of two tab characters.

The line ends with the closing bracket.

I need to add double quotes to part of these lines, as the example below, without changing the five digit number, which is different in all of the many lines.

Code: Select all

		FileName ( "..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s" )
I would be very grateful if you could assist with this.
User avatar
AmigoJack
Posts: 500
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Concluded from what I wrote initially, plus removing the two characters from the start and end of the regular expression, enter the following two lines into the "Replace" dialog window:

Textbox "Find what" must have the following:

Code: Select all

(FileName \( \.\.\\\\\\\\\\\\\\\\\.\.\\\\\\\\\\\\\\\\routes\\\\\\\\\\\\\\\\Chiltern\\\\\\\\\\\\\\\\Dynatrax\\\\\\\\\\\\\\\\DynaTrax-[0-9]{5}\.s \))
Textbox "Replace with" must have the following:

Code: Select all

"$1"
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Post by dforrest »

Jack, we seem to be getting closer but this gives me:

Code: Select all

"FileName ( ..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s )"
where I need:

Code: Select all

FileName ( "..\\\\\\\\..\\\\\\\\routes\\\\\\\\Chiltern\\\\\\\\Dynatrax\\\\\\\\DynaTrax-40055.s" )
User avatar
AmigoJack
Posts: 500
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

forrest, but you do realize that your first post wanted the opposite?

Then make it

Code: Select all

FileName \( (\.\.\\\\\\\\\\\\\\\\\.\.\\\\\\\\\\\\\\\\routes\\\\\\\\\\\\\\\\Chiltern\\\\\\\\\\\\\\\\Dynatrax\\\\\\\\\\\\\\\\DynaTrax-[0-9]{5}\.s) \)
and

Code: Select all

FileName \( "$1" \)
dforrest
Posts: 44
Joined: Mon Jan 19, 2004 11:19 pm
Location: St. Vincent and the Grenadines

Post by dforrest »

Jack, I realise that my first post was in error for which I apologies.

Your latest version does exactly what is needed and you have my sincere thanks for putting up with me and coming up with a solution.

David
Post Reply