douluozhan4370 2019-07-30 19:50
浏览 291

RegEx:如果前缀或后缀匹配,则匹配一个单词(CLOSED)

I am currently looking at my old projects and trying to cleanup the code a little.

I came across a script which matches words in a huge text file if it has a specific prefix (item_name_) or suffix (_item_name).

It matches words like:

  • item_name_foo > foo

  • bar_item_name > bar

Looking at the regex itself made me think this could be improved because of the redundant \w+ between the lookarounds. (?<=item_name_)\w+|\w+(?=_item_name)

So playing around i came up with this: (?<=item_name_)\w+(?=_item_name)

This does not match anymore. Can my old regex even be improved?

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 Stata 面板数据模型选择
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用