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

I have a form value that I need to add a regular expression to the end so I can pick up any characters after the form value. Example if someone enters Jones then I want to make sure the value could also search Jones Jr or Jones Sr or Jones abc etc. Basically add a space and any characters a-z to the form value.

Replies are listed 'Best First'.
Re: Add characters to search value
by linuxer (Curate) on May 22, 2009 at 00:32 UTC

    What have you tried so far?

    How did you implement the search?

    #!/usr/bin/perl -l use strict; use warnings; my @names = ( 'Jones', 'Jones Jr', 'Jones Sr', 'Jones abc', 'Jones ', ); # may be filled from form value my $search = 'Jones'; my @regex = ( # simple qr{\Q$search\E}, # anchored qr{^\Q$search\E$}, # anchored and extended qr{^\Q$search\E(?:\s+\w+)?$}, ); for my $regex ( @regex ) { print "\n\n$regex"; for my $name ( @names ) { print "matched: $name" if $name =~ $regex; } } __END__

    Beware; there's still room for improvement. Try that example and examine the results.

      Thanks for your example and time. It helped me alot.