Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can actual Perl Regular Expressions be implemented in Java via existing library?

Tags:

java

regex

perl

Is there an existing robust Java library which implements a fairly substantial subset of Perl regular expression syntax?

Background:

I wish to implement a file renamer where renaming is done using Perl regular expressions.

The trick is that the project containing said renamer as a component is, currently, 100% in Java in Windows.

NOTES:

I am setting aside the obvious workaround of "install Strawberry Perl; write the whole renamer in Perl (or teach Perl to the developer doing Java coding), pass a list of files to rename to the Perl renamer script via a system call from Java" as too crafty and too obvious :)

Also, please don't offer comparisons of how Java's latest and greatest RegEx engine is already good enough to do most of what Perl RegEx does - I'm fairly aware of its functionality (and can google); thus I already know that said statement might even be true; it is, however, irrelevant to my interest in seeing real Perl RegEx syntax implemented as a Java library.

like image 979
DVK Avatar asked Dec 08 '22 05:12

DVK


2 Answers

Have you tried JRegex? It boasts Perl 5.6 compatibility and doesn't have the worries of linking PCRE in directly.

like image 63
pestilence669 Avatar answered Jan 10 '23 19:01

pestilence669


For maximum Perl compatibility you would need to actually use Perl. You can do that using Inline::Java::Callback, which is distributed as part of the Inline::Java module.

See also: How can I call Perl from Java?

like image 26
Michael Carman Avatar answered Jan 10 '23 21:01

Michael Carman