dop2144 2014-03-27 20:53
浏览 12
已采纳

PHP正则表达式 - 忽略括号并加倍我

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]+)
  • 写回答

1条回答 默认 最新

  • duanjianfu1398 2014-03-27 20:56
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 谁会做这个啊#ensp#Boson NetSim
  • ¥15 如何编写针对TPS6503320FRGE型号的电源管理芯片的编程代码?
  • ¥15 设计简单目录管理系统,要满足以下内容
  • ¥15 关于九十度混合耦合器信号分析问题
  • ¥15 Cesm如何关闭不用的模块呢
  • ¥15 vue2两层数据导出为excle
  • ¥15 有人能帮我做一下这个项目吗
  • ¥15 网络上传速率比下载速率高
  • ¥15 (标签-游戏|关键词-网页游戏)
  • ¥15 这个咋搞🥹可能需要手把手教