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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



anilm
stranger

Jul 9, 2001, 1:55 PM

Post #1 of 4 (6140 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
--anilm




sigma
stranger

Jul 30, 2001, 11:03 AM

Post #2 of 4 (6108 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"; }


anilm
stranger

Jul 30, 2001, 11:46 AM

Post #3 of 4 (6104 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...





abstracts
Novice

Jul 31, 2001, 5:12 AM

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

Hello,
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:

Code
$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,,,

Aziz,,,


 
 


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

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