Page 1 of 1

Replacing Regular Expressions

Posted: Tue Jun 18, 2013 5:37 pm
by dforrest
I have until recently been able to replace strings based on regular expressions in multiple documents but cannot now do this.

Can anyone assist?

I am trying to replace:
Coupling (\n Type ( chain )\n Spring (\n Stiffness ( 1e6N/m 5e6N/m )\n Damping ( 1e6N/m/s 1e6N/m/s )\n Break ( 5.1e7N 5.1e7N )\n r0 ( 20cm 30cm )\n )\n Velocity ( 0.1m/s )\n )\n Coupling (\n Type ( chain )\n Spring (\n Stiffness ( 1e6N/m 5e6N/m )\n Damping ( 1e6N/m/s 1e6N/m/s )\n Break ( 5.1e7N 5.1e7N )\n r0 ( 20cm 30cm )\n )\n Velocity ( -0.1m/s )\n )\n Buffers (\n Spring (\n Stiffness ( 1e6N/m 5e6N/m )\n Damping ( 1e6N/m/s 1e6N/m/s )\n r0 ( 0m 1e9 )\n )\n Centre ( 0.5 )\n Radius ( 1 )\n Angle ( 0.5deg )\n )\n
With:
\n Coupling ( \n Type ( Chain ) \n Spring ( \n Stiffness ( 1e6N/m 5e6N/m ) \n Damping ( 1e6N/m/s 5e6N/m/s ) \n Break ( 1e8N 1e8N ) \n r0 ( 20cm 40cm ) \n ) \n Velocity ( 0.1m/s ) \n ) \n\n Coupling ( \n Type ( Chain ) \n Spring ( \n Stiffness ( 1e6N/m 5e6N/m ) \n Damping ( 1e6N/m/s 5e6N/m/s ) \n Break ( 1e8N 1e8N ) \n r0 ( 20cm 40cm ) \n ) \n Velocity ( -0.1m/s ) \n )\n\n
And get the error message "Cannot match regular expression".

Posted: Tue Jun 18, 2013 6:28 pm
by ben_josephs
Have you changed the version of TextPad you're using? If you're using version 6 or earlier, have you changed the style of regex you're using?

Posted: Tue Jun 18, 2013 8:56 pm
by Drxenos
Instead of trying to debug such a large expression. Start with a small one, make sure it matches, and incrementally build up.

Posted: Tue Jun 18, 2013 9:04 pm
by ben_josephs
Very good advice.

Posted: Tue Jun 25, 2013 7:21 pm
by dforrest
ben_josephs wrote:Have you changed the version of TextPad you're using? If you're using version 6 or earlier, have you changed the style of regex you're using?
Yes I have recently upgraded to the latest version of TextPad. Sorry, I do not understand about regex.

.

Posted: Tue Jun 25, 2013 7:23 pm
by dforrest
Drxenos wrote:Instead of trying to debug such a large expression. Start with a small one, make sure it matches, and incrementally build up.
The fist expression is a "copy" of an actual section of the document. The second expression is a "copy" of a section of another document.

Posted: Tue Jun 25, 2013 8:48 pm
by ben_josephs
You are asking us to guess what you are trying to do.

Do the "\n"s represent newlines or are they literal "\n"s?
Do you want an extra "\n" (literal or otherwise) introduced between Coupling sections?
Do you want all Buffer sections deleted?
Do you want the Type "chain" always to have its initial capitalised?
What is the rule for adjusting the Damping value? ("1e6N/m/s 1e6N/m/s" appears to change to "1e6N/m/s 5e6N/m/s".)
What is the rule for adjusting the Break value? ("5.1e7N 5.1e7N" appears to change to "1e8N 1e8N".)
What is the rule for adjusting the r0 value? ("20cm 30cm" appears to change to "20cm 40cm".)
Etc...

Posted: Thu Jun 27, 2013 6:50 pm
by Drxenos
dforrest wrote:
Drxenos wrote:Instead of trying to debug such a large expression. Start with a small one, make sure it matches, and incrementally build up.
The fist expression is a "copy" of an actual section of the document. The second expression is a "copy" of a section of another document.
How does that negate the fact it is much too large and complex for us to easily tell you why it doesn't work the way you want it to?

Posted: Fri Jun 28, 2013 10:03 pm
by dforrest
In the past I have cheched "Regular expression" in the "Replace" dialogue box and copied the block I want to replace and pasted this into the "Find what"" box.

I have similarly copied and pasted the block of text I want it reppaced with into the "Replace with:" box (I copy this from onother document).

I the check "All documents" and choose "Replace All" and all occurances of the first block are replaced by the second block.

This does not appear to work with the latest version of TextPad.

Posted: Fri Jun 28, 2013 10:21 pm
by ben_josephs
That couldn't have worked with your example in any version of TextPad, because of the backslashes and, depending on version and settings, the parentheses.

You still haven't answered the points raised by Drxenos and me, and you are still expecting us to guess what you want.

If you want help you will have to put as least as much effort into your questions as you expect others to put into their answers.

Posted: Mon Jul 01, 2013 6:44 pm
by dforrest
Ben, I cannot answer you points becuase I do not know the answers. I have previously been able to highlight a block of text, with "Regular expression" chosen, and replace it in all open documents with another block of text chosen. For some reason, I cannot now do this.

David

Posted: Mon Jul 01, 2013 8:44 pm
by ben_josephs
If you want to replace literal text with literal text, why are you selecting Regular expression? Try deselecting it.

Posted: Tue Jul 02, 2013 1:30 pm
by dforrest
ben_josephs wrote:If you want to replace literal text with literal text, why are you selecting Regular expression? Try deselecting it.
When I do that I get the message "Cannot find literal text:".

Posted: Wed Jul 03, 2013 1:14 pm
by dforrest
This thread appers to explain why I am having the problem:

http://forums.textpad.com/viewtopic.php?t=12384

I have successfully made the change (to about 150 documents) by using WildEdit.

.