Regular Expression help with search ranges and replacing

27 views
Skip to first unread message

Lloyd Goss

unread,
Jul 23, 2024, 7:13:52 PM (4 days ago) Jul 23
to BBEdit Talk
How do you carry over a result of a range like [0-9] to the replace side.

So that when "Jn[0-9][0-9]_"  finds "Jn12_" the 12 (or and pair of digits) carries over to the replacement.

My goal is to replace all occurrences of the ending "_" with a "."

So "Jn01_" becomes "Jn01." 
So "Jn12_" becomes "Jn12." 

Thanks in advance.

Tom Robinson

unread,
Jul 23, 2024, 7:19:10 PM (4 days ago) Jul 23
to BBEdit Talk
'Capture buffers' are the answer.

Find:

(Jn[0-9][0-9])_


Replace with


\1.


Left bracket starts the capture, right bracket finishes it, \1 references what was between the brackets.  You can have more than 1 set of brackets, then use \2 for the 2nd, etc.


(Formatting brought to you by BBEdit’s Copy as Styled Text)


Cheers

Marsden Broadbent

unread,
Jul 26, 2024, 6:58:04 AM (yesterday) Jul 26
to bbe...@googlegroups.com
Try capturing your original as ("Jn\d+)_(")
And replace with \1.\2 
This should replace the _ with a . (full stop or is that "period" to you?) in both cases 
Cheers Marsden

--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/A2DEB7E1-4C63-4237-A0A1-79141FE09C2F%40gmail.com.
Reply all
Reply to author
Forward
0 new messages