On Jul 27, 2007 Daniel Farnworth wrote:

> Hi,
> 
> I have an XML document within which I need to comment out various
> '<dict>...</dict>' sections.
> 
> Can anybody suggest a search pattern I can use to find this type of pattern
> and replace with <!--<dict>...</dict>-->

Hi Daniel

I'm going to have a go.

Find:

<dict>(?s).+?</dict>

Replace:

<!--&-->

Here's an attempt at an explanation

<dict>

Finds the first incidence of that

.

Finds any character that isn't a return

.+

Finds one or more of that character, however that will include the characters 
in </dict> and after and we want the search pattern to end there so we put

?

after .+ to tell it to only to search until the next defined characters in 
the search expression are found.

It might well be that there are return characters between <dict> and </dict> 
in the file so we put a switch to tell

.

to find return characters, turning it into something that will find anything.
The switch is like this:

(?s)

So, in the middle we have:

(?s).+?

after it we put </dict> to say that where the searched selection is going to 
end.

Now for the replace that is simple because we can "match all of the search 
expression" using:

&

as you want the <!-- and --> before and after then the replace expression is:
<!--&-->

There is one caveat which is that if you have <dict> nested it will go wrong.
<dict>some stuff<dict>some stuff</dict>some stuff</dict>

will become

<!--<dict>some stuff<dict>some stuff</dict>-->some stuff</dict>

so as long as there are no nested <dict> then it will, I hope be okay.


-- 
Patrick
<http://www.patrickjames.me.uk>



-- 
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to