From: Elegie on
RobG wrote:

Hello Rob,

<snip>

> However, sometimes the expression
> includes an attribute value that has slashes. In that case, I don't
> want to modify the attribute value's slash. e.g. at the moment,
>
> /LandXML/Parcels/Parcel[@name="79a/SP199095"]
>
> is converted to:
>
> /xx:LandXML/xx:Parcels/xx:Parcel[@name="79a/xx:SP199095"]
>
>
> Modifying the attribute value means that the result will be wrong. Is
> there a regular expression that will only modify slashes outside
> square brackets?

The following should give you some path worth walking :)

---
(s).replace(
/\/([^[/]*(\[(\\.|[^\\\]]*)*\])?)/g,
"/xx:$1"
)
---

HTH,
Elegie.
From: Antony Scriven on
On Mar 25, 8:49 pm, Elegie wrote:

> > [...] In that case, I don't want to modify the
> > attribute value's slash. e.g. at the moment,
>
> > /LandXML/Parcels/Parcel[@name="79a/SP199095"]
>
> > is converted to:
>
> > /xx:LandXML/xx:Parcels/xx:Parcel[@name="79a/xx:SP199095"]
>
> > Modifying the attribute value means that the result
> > will be wrong. Is there a regular expression that will
> > only modify slashes outside square brackets?
>
> The following should give you some path worth walking :)
>
> ---
>    (s).replace(
>      /\/([^[/]*(\[(\\.|[^\\\]]*)*\])?)/g,
>      "/xx:$1"
>    )

Well, if you like brittle one-liners, try this.

var s = '//LandXML/Parcels/Parcel[@name="]7]' +
'9a/S\\"P19[9\\"]0/9[/5"]/Blah';

// Add xx: after slashes, only if they are not within "...".
// Handles \" within "...".
s.replace(
/(\/+)(("([^"]*\\.)*[^"]*"|[^\/])+)/g,
'$1xx:$2'
);

There might be a neater regexp but I'm beginning to lose
the will! And yes, this is now beginning to resemble line
noise. --Antony