in reply to how can i split a string to an array and convert it into regular expression
i want to split it into an array becoz i want to convert the user input into regular expression with some loops
You don't need to split into an array of characters for performing the task you described. The "program" you'll need looks probably like:
... my $input = <STDIN>; chomp $input; my $regex; $regex = transform_string_to_optimal_matching_regex($input); if( $input =~ /$regex/ ) { print "regex |$regex| to input |$input| mapping succeeded\n"; } ...
Perl is really good at finding strings that match a given regular expression, but rather bad at finding regular expressions that *would match* given strings 'optimally'. The remaining task for you is therefore to enter your favorite algorithm to do that between the curly braces of the subroutine 'transform_string_to_optimal_matching_regex()':
sub transform_string_to_optimal_matching_regex { my $given_string = shift; my $regex = ''; my $optimal_solution_found = 0; while(! $optimal_solution_found ) { # # construct optimal regex by some # stochastic algorithm, possibly # long running Monte Carlo-solver # } return $regex; }
This is really an interesting thing to do. Maybe there are some approaches already published (none of which I know from).
Regards
mwa
|
|---|