Search, Use Result to Add Code
-
I have an xml file that needs to be modified.
I need to search for a callout that has an argument numref, as shown in the code below:<callout assocfig="fig3" numref="c3"/>
Then, take the number after “c” and insert it before the numref in an argument, label, as below:
<callout assocfig="fig3" label="3" numref="c3"/>
Thanks in advance!
-
You have asked many such questions here.
We are not a “substitution” service.
Suggest you take what you’ve learned along the way, couple it with reading the documentation on regular expressions, and at least come up with a stab at it before asking for further help. -
Hey, I’m just happy I formatted the question properly, using Code. :)
I do get your point and if this is inappropriate, ok.
Thanks. -
@richard-howard said in Search, Use Result to Add Code:
Thanks in advance!
Replace:
Find what:
(numref\s*\=\s*\"c(\d)\")
Replace with:label="\2" \1
Search mode: Regular expressionThat’s your one freebie. Happy weekend, Happy Holidays … as the requirements change based on forthcoming further clarification, you can manipulate / improve the base I provided above to get you started.
Cheers.
-
Your generosity is appreciated!
Happy Holidays to you all!! -
@richard-howard Just an update. The solution I was offered was very helpful. It did find and replace as desired, but the find only matched single numeric characters. Where the “C” was followed by double digits, it did not find it. So, after your ‘encouraging me’ to do a little research before just asking for the answer, I found something that works.
To find double digits, I replaced:(numref\s*\=\s*\"c(\d)\")
with:
(numref\s*\=\s*\"c(\d[0-9])\")
Undoubtedly, this is not the only, or best, solution, but it does appear to work, though requires 2 passes to complete all matches. Just thought you might like to know that your nudge helped.
Thanks. -
@richard-howard said in Search, Use Result to Add Code:
So, after your ‘encouraging me’ to do a little research before just asking for the answer, I found something that works.
Excellent! And in the spirit of collaboration and your research and reporting back, you could try replacing
\d
in my suggestion with\d+
where the+
in REGEX syntax means "match at least one of the previous characters - in this case\d
which is a digit. So\d+
is “one or more digits” - like “3”, “34”, “1337”, etc…Cheers.
-
@richard-howard said in Search, Use Result to Add Code:
…
\d[0-9]
…Good job on taking the initiative.
Two hints for learning more:
You might want to look at what
\d
means, in the docs regarding character escape sequences.You might want to look at the docs regarding multiplying operators, looking for something that means “one or more”.
Combining those two will simplify your expression, and make it easier to catch c3, c31, and c314 all with the same expression.
… ah, @michael-vincent beat me to the punch… I’d still recommend actually reading the sections of the manual that I linked.
-
@michael-vincent Excellent! This forum has saved me uncounted hours. I appreciate it very much.
-
@richard-howard said in Search, Use Result to Add Code:
So, after your ‘encouraging me’ to do a little research before just asking for the answer, I found something that works.
Awesome. You can only get better by taking such initiative.