Can replace expression substitute characters?

General discussions about Advanced Find and Replace
Post Reply
kjustian
Posts: 6
Joined: Fri Jan 20, 2006 11:22 pm

Can replace expression substitute characters?

Post by kjustian » Tue Jan 24, 2006 4:31 pm

If I use the following regex

Find
\{C_([A-Za-z0-9]*)_Panelview(.)(?:0)?(\d*)(_)?(?:0)?(\d*)?\}

Replace
{[PLC_05052]C_$1_Panelview[$3]$5}

Example text block before
{C_OP700_Panelview_424}
{C_OP700_Panelview_00}
{C_OP700_Panelview_10_00}
{C_OP700_Panelview_06_10}
{C_OP700_Panelview_32}
{C_OP700_Panelview_10_11}
{C_OP700_Panelview_500}
{C_System_Panelview_424}
{C_System_Panelview_00}
{C_System_Panelview_10_00}
{C_System_Panelview_06_10}
{C_System_Panelview_32}
{C_System_Panelview_10_11}
{C_System_Panelview_500}

Example text block after
{[PLC_05052]C_OP700_Panelview[424]}
{[PLC_05052]C_OP700_Panelview[0]}
{[PLC_05052]C_OP700_Panelview[10]0}
{[PLC_05052]C_OP700_Panelview[6]10}
{[PLC_05052]C_OP700_Panelview[32]}
{[PLC_05052]C_OP700_Panelview[10]11}
{[PLC_05052]C_OP700_Panelview[500]}
{[PLC_05052]C_System_Panelview[424]}
{[PLC_05052]C_System_Panelview[0]}
{[PLC_05052]C_System_Panelview[10]0}
{[PLC_05052]C_System_Panelview[6]10}
{[PLC_05052]C_System_Panelview[32]}
{[PLC_05052]C_System_Panelview[10]11}
{[PLC_05052]C_System_Panelview[500]}

Can I substitute the $4 with the literal character "."? What would the syntax be? This is sort of a general question because AFR is not the only tool I use for this type of work.

Also, there was another post on the board where it was suggested that there is plenty of help for you to eventually figure out the syntax for the match (RegexBuddy has been helping me ;), but no good help for the replacement (expressions?). It seems reasonable since the program really has two parts - search AND replace that they should both be adequately documented. Not that I am knocking the response time on the forum, just wishing I did not have to resort to using it.

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Re: Can replace expression substitute characters?

Post by Abacre » Tue Jan 24, 2006 6:06 pm

kjustian wrote:Can I substitute the $4 with the literal character "."? What would the syntax be? This is sort of a general question because AFR is not the only tool I use for this type of work.


Normally you should put "." (without quotes) into Replace With part in
place of $4.

BTW are you sure that
Search for:
\{C_([A-Za-z0-9]*)_Panelview(.)(?:0)?(\d*)(_)?(?:0)?(\d*)?\}
worked fine?

The syntax of regular expressions used in AFR is explained here:
http://www.abacre.com/afr/manual/regexpsyntax.htm
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

kjustian
Posts: 6
Joined: Fri Jan 20, 2006 11:22 pm

Post by kjustian » Tue Jan 24, 2006 6:42 pm

\{C_([A-Za-z0-9]*)_Panelview(.)(0)?(\d*)(_)?(0)?(\d*)?\}

No, I did have to change it like this... :oops:

But in this case, I do not always want to replace $4 with a "." - only if the value is "_". I do not use $2 in the replacement string because I will always replace it with the "[". Maybe there is a better way to do the same thing, but this was the way I figured out how to do it (most of the way). :cry:

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Tue Jan 24, 2006 9:33 pm

Why don't you use r.e. provided in:
http://www.abacre.net/forums/viewtopic.php?t=223
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

kjustian
Posts: 6
Joined: Fri Jan 20, 2006 11:22 pm

Post by kjustian » Tue Jan 24, 2006 10:57 pm

When I tried this, some lines had too many replacements. So instead of asking right away, I thought it would be better to try and learn how for myself. I have been using Textpad for a few years and have had mixed success with RE before. Now there seems to be more books and other tools available as well as more programs using it. The project I am working on needs many changes and lot of them can be done in xml text files. Since I found your program last, it is still unfamiliar compared to my other tools and my brain needs to be adjusted to use the available methods properly. Thanks for your patience.

kjustian
Posts: 6
Joined: Fri Jan 20, 2006 11:22 pm

Post by kjustian » Tue Jan 24, 2006 11:02 pm

Oh, and I forgot to ask - what were the options (and/or modifiers) to make http://www.abacre.net/forums/viewtopic.php?t=223 work?

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Wed Jan 25, 2006 9:25 pm

You should use it with default settings:
Modifier S: OFF
Modifier M: ON
Modifier I: ON
Modifier G: OFF
Modifier X: OFF
Modifier X: OFF
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests