replace \d with { \d}

59 views
Skip to first unread message

RF

unread,
Oct 23, 2017, 7:33:48 AM10/23/17
to TextWrangler Talk
Hi, Trying to LaTeX some bible passages and need to replace [n] with \textsupercript{n} 
Where 'n' = any number.

Eg: Replace [23] with \textsuperscript{23}


I think grep is my friend.

I tried this:
Find: \[\d+\]
Replace: \\textsuperscript{\d+}

the replacement is:
\textsuperscript{d+} which I suppose is fairly predictable. 

Any ideas how I need to amend the replace expression to produce the effect I need please?

Thank you.

Patrick Woolsey

unread,
Oct 23, 2017, 8:20:13 AM10/23/17
to textwr...@googlegroups.com
To obtain the desired result, you'll need to capture the number
in a _subpattern_ by enclosing that part of your Find pattern in
parentheses (\d+) so:

Find: \[(\d+)\]

and then insert the matched number by referencing the first (and
only :-) subpattern \1 in your Find pattern:

Replace: \\textsuperscript{\1}

and that should do the job.


[PS: For much more info about creating and using grep patterns,
please see Chapter 8 of the included PDF manual, which you can
access at any time via Help -> User Manual.]


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com/>

RF

unread,
Oct 23, 2017, 10:52:19 AM10/23/17
to TextWrangler Talk
Solved. Thank you so much Patrick, it worked a treat. Yes, indeed the Manual does make sense now I know what I was looking for. Many thanks again. Robert
Reply all
Reply to author
Forward
0 new messages