wikispooks
2013-04-04
I'm not a programmer so please bear with me. The below example concerns manipulating back-forth referencing in html footnotes - fairly obvious I guess. I find my self having to do masses of this in existing documents for both wikitext and html where the links are messed up or otherwise not properly implemented. I need something beyond regular find/replace with manual editing of the footnote numbers themselves.
Example:
Search
<a href="#refx">[x]</a>
Replace with
<a href="#refx" name="refx">[x]</a>
where the x,s can be anywhere between 1 and say 500
I've had a quick look around the regular expressions section of the wiki and will probably get there by myself eventually, but any help from the forum would be much appreciated.
wikispooks
2013-04-04
I've got as far as finding the strings OK with single digits using:
(<a href="#ref.">\[.\]</a>)
Also I can find the double and triple digits using 2 or 3 dots.
But I'm struggling to get close to a workable replace. Also it would be good to do the job in one pass.
I guess I should have put this the help section; sorry.
Dave Brotherstone
2013-04-04
You can use [0-9]{1,3}
to mean between 1 and 3 digits, instead of just a dot.
You don't need the brackets around the whole expression, but adding brackets around the ([0-9]{1,3})
means you can use $1 in the replace expression to mean "whatever was found in the first bracketed expression". $2 would refer to the second set of brackets if you needed that.
wikispooks
2013-04-04
Thanks a bunch Dave
I'm nearly there and your post ought to clinch it.
I'll post what I finally come up with but may not be until tomorrow now
wikispooks
2013-04-04
Well, I couldn't get the curly braces {1,3} to work. I restricted the search to just the known unique parts - ie #ref plus the number.
This is what I finally came up with and it's a good time-saver for now so I'm reasonably happy:
Search
"#ref([0-9]*)"
Replace
"#ref\1" name="ref\1"
THEVENOT Guy
2013-04-05
Hi wikispooks,
If the form {n,m}
don't work for you, you probably use a version
of N++ prior to the 6.0 one !
Just for info, it's possible to simplify the replace part :
If your version of N++
is lower than 6.0 :
SEARCH : "#(ref[0-9]+")
REPLACE : "#\1 name="\1
If your version of N++
is 6.0 or greater than 6.0 :
SEARCH : "#(ref[0-9]+")
or "#(ref[0-9]{1,3}")
REPLACE : $0 name="\1
Note : $0 represents the totality of the searched string
Best regards,
guy038
P.S. You can find good documentation, about the new PRCE Regular Expressions, used by N++, from the 6.0 version, at the two adresses below :
http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
The FIRST one concerns the syntax of regular expressions in the SEARCH part
The SECOND one concerns the syntax of regular expressions in the REPLACEMENT part
wikispooks
2013-04-05
Hi Thevenot
As usual I've found that there's no substitute for a bit of concentrated study/learning.
Thanks for the additional info - v useful. I was using a 5.9.xxx version so that explains the curly braces problem.
The exercise has opened up a new world of possibilities for Notepad++