regex compression?

B

Bill

Hello,

I wonder if anyone is aware of a package that will rewrite a set of
regex patterns to reduce their number. For example, given the four
regex patterns

/all\d+ of the/
/crab.*apple tree/
/all 3 of them/
/crabapple tree/

reduce to something like

/crab.*apple tree/
/all\d+ of them?/

that will match the same set of strings.

I don't need something that just does an 'or' of all the supplied regexes
into one though.
 
B

Brian McCauley

I wonder if anyone is aware of a package that will rewrite a set of
regex patterns to reduce their number.

This question is oft asked here in various guises and I think the
answer is "no". I think the problem is quite possibly "hard" (in the
CS sense of the word).
For example, given the four
regex patterns

/all\d+ of the/
/crab.*apple tree/
/all 3 of them/
/crabapple tree/

reduce to something like

/crab.*apple tree/
/all\d+ of them?/

that will match the same set of strings.

Actually it won't.

Even if I discount the missing space between /all/ and /\d+/ as a typo
it still won't.
I don't need something that just does an 'or' of all the supplied regexes
into one though.

Why?

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
B

Bill

Even if I discount the missing space between /all/ and /\d+/ as a typo
it still won't.


Why?

I was trying to optimize Mail::Milter::Module::ConnectRegex to make it run
faster. Sorry about the typos above.
 
B

Bill

Brian McCauley said:
This question is oft asked here in various guises and I think the
answer is "no". I think the problem is quite possibly "hard" (in the
CS sense of the word).

Aha, just found Regexp::Optimizer. Silly, I'd been searching CPAN
using 'regex' instead of 'regexp'. Never mind :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top