Friday 17 June 2011

Annother NetBeans annoyance

NetBeans' search and replace dialog allows you to use regex capturing groups in the find string and regex back references in the replace string. But a naive user, who expected to be able to use something like "\1" and "\2" for his back references, would be sorely annoyed when they didn't work.

Instead, NetBeans uses $1, $2, etc. for its back references. As this person found out after perusing the source code for the search and replace dialog.

The reason, apparently, is because that's what Java regexes do (and Java regexes do what they do because that's what perl regexes do, and always have done). And because NetBeans is primarily a Java-oriented IDE, the Javaness wins out over the regexness, or something.

All of which would be but a minor annoyance, were it not for the information that you're offered when you click the help button in the search and replace dialog, which eventually leads you to a page in the official Java regex documentation that says this:

Back references
\n Whatever the nth capturing group matched

Sigh...

No comments:

Post a Comment