I have a file with some xml tags that follow specific patterns (Name and Props are placeholders)
<Name id="mod:Name"/>
<Prop1 Name id="mod:object.Prop1 Name"/>
<Prop1 Prop2 Name id="mod:object.Prop1 Prop2 Name"/>
<Prop1 Prop2 Prop3 Name id="mod:object.Prop1 Prop2 Prop3 Name"/>
I am looking for regex to remove whitespace from portion before the "id=..."
How this should look
<Name id="mod:Name"/>
<Prop1Name id="mod:object.Prop1 Name"/>
<Prop1Prop2Name id="mod:object.Prop1 Prop2 Name"/>
<Prop1Prop2Prop3Name id="mod:object.Prop1 Prop2 Prop3 Name"/>
I have seen the (\S+)\s(?=\S+\s+)
example with the substitution being just \1
but that removes all the spaces except the last one and doesn't leave a space before the id=
<Name id="mod:Name"/>
<Prop1Name id="mod:object.Prop1 Name"/>
<Prop1Prop2Name id="mod:object.Prop1Prop2 Name"/>
<Prop1Prop2Prop3Name id="mod:object.Prop1Prop2Prop3 Name"/>
I tried something like
^((\S+)*)\s((\S+)*)\s((\S+)*)\s((\S+)*)\s(?=id)
But that gave me catastrophic backtracking
Not sure if it helps but Sublime uses Boost regex
First question on The Stack so any improvements on question would be welcome
Thank you
This seems to work
^(?|((\S+))\s|((\S+)\s(\S+))\s|((\S+)\s(\S+)\s(\S+)\s))(id=.*)
with replace of $2$3$4 $5
Thanks for the advice