[jedit:feature-requests] #554 add match index to beanshell replace context

Eric Le Lay via jEdit-devel <[email protected]>
Newsgroups gmane.editors.jedit.devel
Message-ID <6290a0a02b823c397b9d731d.feature-requests@jedit.p.sourceforge.net>


---

** [feature-requests:#554] add match index to beanshell replace context**

**Status:** open
**Group:** none
**Created:** Fri May 27, 2022 09:57 AM UTC by Eric Le Lay
**Last Updated:** Fri May 27, 2022 09:57 AM UTC
**Owner:** nobody


My use case is generating unique names to import RAM dimms in netbox: using dmidecode and grep I have a list of serial numbers, one per line. I want to generate the text "ramN,THE_SERIAL" using search/beanshell replace:
- search `(.+)`
- replace with `"ram" + index + "," + _0`

Padding, etc can be done by String.format, even if it's a bit ugly because beanshell doesn't understand vararg methods so the argument must be wrapped in an array: `String.format("ram%03d", new Object[]{index}) + "," + _0`

It could also be used to renumber markdown lists:
- search `^(\s+)[0-9]+\. )`
- replace with `_1 + index + ". "`

Or to compute simple odd/even classes in a table
- search `<tr>`
- replace with `"<tr class=\"" + (index % 2 == 0? "even" : "odd") + "\">"`




---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/jedit/feature-requests/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/jedit/admin/feature-requests/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.

-- 
-----------------------------------------------
jEdit Developers' List
[email protected]
https://lists.sourceforge.net/lists/listinfo/jedit-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.