dongxingchang9345 2016-07-27 13:54
浏览 68

在字符串正则表达式之前提取值

i have a question, need to extract a value before a defined string, but i can't, for example need to extract the value "Pudahuel", this word (dinamic) It is before the word "Horario", any suggestions?

 Orden de Trabajo
                                                            N° 0200087663


                                                                 Pudahuel Horario Atención: LU a VI de 08:30 a 13:00 y 14:30 a 19:00
Datos de Recepción:

example link: https://regex101.com/r/zN2vG6/29

  • 写回答

2条回答 默认 最新

  • douba4824 2016-07-27 14:05
    关注

    Your (.*)(?=Horario) matches 0+ chars other than a newline (because you did not use the DOTALL modifier) before a Horario text. Note there is a linebreak between the words you need.

    Use the following regex

    (\w+)\s*Horario
    

    See the regex demo

    The value you need will be in Group 1. Instead of \w+ (one or more word chars, those from [a-zA-Z0-9_] range) you may use [a-zA-Z]+, or even \p{L}+ (any 1+ letters).

    NOTE: When you have Unicode chars in the patter/string, you need to use the /u modifier:

    /(\w+)\s*Horario/u
    

    or your suggested pattern (a bit enhanced):

    /N°\s+(\S+)/u
                ^
    
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害