Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Converting Regular Expressions to English

by Anonymous Monk
on May 28, 2002 at 15:42 UTC ( [id://169803]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm considering writing a script, and am curious to know whether something similar already exists. I've tried searching this site, Usenet, and the Web, but as I'm not sure of the correct terms to use I'm having no success.

The basic idea is that it will accept as input a regular expression, and output a detailed explanation in English of what the regex does. Eventually, I'd like it to work the opposite way around as well -- converting English commands to a regex.

Are there any major flaws in this proposal? Are there any references I'd be advised to read? What would the "right way" to approach such a problem?

Thank you. :)

- Ben

  • Comment on Converting Regular Expressions to English

Replies are listed 'Best First'.
Re: Converting Regular Expressions to English
by broquaint (Abbot) on May 28, 2002 at 15:48 UTC
    This has already been done by the regex ninja japhy in the funky YAPE::Regex::Explain module.
    use YAPE::Explain::Regex; my $re = qr/foo*(?<=bar)+?(?:baz)?/; print YAPE::Regex::Explain->new($re)->explain; __output__ The regular expression: (?-imsx:foo*(?<=bar)(?:baz)?) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- fo 'fo' ---------------------------------------------------------------------- o* 'o' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- (?<= look behind to see if there is (1 or more times (matching the least amount possible)): ---------------------------------------------------------------------- bar 'bar' ---------------------------------------------------------------------- )+? end of look-behind ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- baz 'baz' ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

    HTH

    _________
    broquaint

Re: Converting Regular Expressions to English
by davis (Vicar) on May 28, 2002 at 15:45 UTC
    Perhaps chromatic's Regexp::English might be of use?
    cheers
    davis
    Is this going out live?
    No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist
Re: Converting Regular Expressions to English
by mdillon (Priest) on May 28, 2002 at 15:48 UTC
Re: Converting Regular Expressions to English
by zentara (Archbishop) on May 28, 2002 at 18:38 UTC
    Going in the other direction.......................English to Regex. Just for your information, someone has attempted an English to Regex bash2 script. You might look and see the problems he ran into. It's at txt2regex To me, it looks like the biggest problem is optimization. The script makes these clunky drawn out regexes most of the time. I don't think the AI guys can get Japhy's or Krahn's brain into code yet. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://169803]
Approved by mdillon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found