I have three separate strings as follows:
California (Socal)
New Jersey
Ohio II
I want to extract the following string from each respectively:
California
New Jersey
Ohio
So basically I want to drop anything that begins with a parenthesis or a double I. Here is what I have tried but I'm not sure how to proceed:
([a-z]+.[a-z]+)
Using preg_replace
will be easy for this:
$arr = array(
"California (Socal)",
"New Jersey",
"Ohio II"
);
foreach($arr as $a){
$a = preg_replace("/(II|\().*/", "", $a);
}
Here its replacing anything after the II
or (
with empty.