On Fri, Apr 20, 2012 at 09:56:48AM +0200, Roland Küffner wrote:
> Assuming you already did your first step resulting in 
> 
> Am 19.04.2012 um 19, 22:54 schrieb Brad Ummer:
> > <h3><a name="This is some string of variable length">This is some string of 
> > variable length</a></h3>
> 
> You could search for:
> name="(.+?) (.+?)"
> 
> and replace it with:
> name="\1_\2"
> 
> You would have to hit "Replace All" until you get no further hits to
> replace all spaces one by one.

Careful!  name="(.+?) (.+?)" will not do what you want, because there is
nothing keeping the (.+?) from matching past the first quote character.
You'll end up replacing all the spaces from the first occurence of name="
to the last occurence of ".


What you want is:

Find
name="([^"]*?) ([^"]*?)"

Replace
name="\1_\2"


Or even just:

Find (there's a trailing space)
name="([^"]*?) 

Replace
name="\1_


> This is the quick and dirty solution. AFAIK there is no way to do it in
> one go with regular expressions. You would need a script to achieve that
> - of course this could take longer to put together than to hit "Replace
> All" a few times.

Right, you need to do a loop within a loop, which you can't do with a
straightforward find & replace.


Here's one way to do it, in Perl:

#!perl -pi
s/name="([^"]*)"/ ($x = $1) =~ tr, ,_,; qq{name="$x"} /ge;

Ronald

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to