On Wed, Sep 18, 2013 at 11:22:04AM -0700, [email protected] wrote:

> In the example, I wish to update a tag with the 'bar' attribute giving it a 
> specific value whether the attribute exists or not. I can do this but not 
> without sometimes ending up with duplicating thet attribute or issues like 
> that.
> since I don't know what if any other attributes may be on each side of the 
> 'bar="..."' attribute my efforts have started off as something like the 
> following:
> http([^"]+)"([^>]*)(bar="that"|)([^>]*)>
> 
> However because of the need to use ([^>]*) to try and capture possible 
> other unknow attributes, the following (bar="that"|) doesn't make sense 
> because the previous group could include bar="that" and match the second 
> half of (bar="Product"|)
> 
> examples of the result I'm wondering if I can achieve with a single regex.
> a
> find
> <a href="example1" foo="this" bar="that" alt="maybe">
> replace
> <a href="example1" foo="this" bar="example1" alt="maybe">
> 
> b
> find
> <a href="example1" foo="this" alt="maybe">
> replace
> <a href="example2" foo="this" bar="example2" alt="maybe">
> 
> Is it possible and if so, how?

If I understand what it is you're trying to do, this might work:

Find
(<a\s+(?:(?!\sbar=)[^>])*)(?:\sbar="[^"]*")?([^>]*>)

Replace
\1 bar="example1"\2


(?:(?!\sbar=)[^>])* matches one character, other than >, at a time, but
stops if \sbar= matches at the current point in the string.


Ronald

-- 
This is the BBEdit Talk public discussion group. 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>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to