CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
pattern from a string



Jul 9, 2001, 1:55 PM

Post #1 of 4 (19539 views)
pattern from a string Can't Post

hello friends,
May be a crazy thought,
Is there any scripts available to get a pattern from the statement.
is anyone knows please let me know.

If not, most welcome with ideas to create such scripts to generate a regular expression.

thanks in advance


Jul 30, 2001, 11:03 AM

Post #2 of 4 (19507 views)
Re: pattern from a string [In reply to] Can't Post

What should do that magic script? I think, your question is not understandable.

for ($!=0;$!<123;$!++) { print "$!\n"; }


Jul 30, 2001, 11:46 AM

Post #3 of 4 (19503 views)
Re: pattern from a string [In reply to] Can't Post

Why every one writing a pattern to match the string, etc...
why not in reverse...
By just providing the string, an application or script should give the
proper matching pattern.

May be a crazy thought.
just want to find out is any one written that sought of.
If not interested in writing such scripts (no plans yet....)
or application making life easier...


Jul 31, 2001, 5:12 AM

Post #4 of 4 (19494 views)
Re: pattern from a string [In reply to] Can't Post

If I'm understanding correctly, you want to derive a regexp from a string. Or you wonder why no one has done so before.

The simple answer is "you can't". You can write a program to generate a regexp that would match a given string but that's trivially simple, just use the same string (after doing proper escaping) and you have a regexp that matches this string. Example:

$string = "Hello"; 
my $regexp = "/\Q$string\E/"; # this would match only the string above
my $regexp = "//"; # and this would match the string above

Do you see the problem there? There are (countably) infinite number of regular languages that accept a given input. A program can just enumerate all possible regular expressions that could match the given string. It's you, the programmer, who can tell which one should be chosen. Regular languages (and expressions) are just a very concise and practical way of describing what should or should not be matched.

Hope this clarifies,,,



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives