May 2021 1 73 Report
Perl Regular Expression Help?

I have an array of cities and I would like it to return true if someone types in all or part of a city name. So "lak" ,"l", and "lakesi" would all return true for "lakeside". It must be spelled correctly, I am not just trying to match some letters in a city name and it must start from the beginning of the word, so "lksd" and "kside" would return false. Can you tell me a regular expression to do this?

example:

$city = <STDIN>;

foreach $mycity (@cities_array)

{

if($city =~ [some regex stuff]/$mycity/)

{

print "Some Output";

}

}

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.