douniewei6346 2015-09-15 10:32
浏览 52
已采纳

正则表达:一句话之前的一切

I have the following text:

There are 12.800.500 sorts of animals.

Now, I want to get 12.800.800 as the output, when I search for "sorts". How could I do that? I tried

\d+(?= sorts)

but this gives me only "500" as a result and not the whole number with dots. How can I make sure I get "everything" before "sorts" until the first space?

Thanks!

  • 写回答

1条回答 默认 最新

  • duanniwu7730 2015-09-15 10:34
    关注

    The text you're trying to match also includes DOTS not just digits so use this regex:

    \b[\d.]+(?=\s+sorts)
    

    RegEx Demo

    [\d.] will match either a digit or a DOT.

    To match any non-space character use:

    \S+(?=\s+sorts)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本