[jedit:feature-requests] #554 add match index to beanshell replace context
Eric Le Lay via jEdit-devel <[email protected]> Sun, 17 Sep 2023 18:23:45 -0000
| Newsgroups | gmane.editors.jedit.devel |
|---|---|
| Message-ID | </p/jedit/feature-requests/554/dcea000e3445b81726da9a130785341659158b5d.feature-requests@jedit.p.sourceforge.net> |
- **status**: open --> closed-fixed
- **Comment**:
implemented in [r25683](https://sourceforge.net/p/jedit/svn/25683/)
---
**[feature-requests:#554] add match index to beanshell replace context**
**Status:** closed-fixed
**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