doujuan2688 2015-07-02 04:12
浏览 54
已采纳

RegEx提取minecraft mods名称[关闭]

[17] => Link_Info-mc1.7.10-0.3.1.litemod
[18] => Mantle-1.7.10-0.3.2.jar
[19] => MicdoodleCore-1.7-3.0.11.333.jar
[20] => MineTweaker3-1.7.10-3.0.9C.jar
[21] => ModTweaker 2-0.8.0.jar
[22] => MouseTweaks-2.4.4-mc1.7.10.jar
[23] => NEIIntegration-MC1.7.10-1.0.9.jar
[24] => NotEnoughItems-1.7.10-1.0.5.110-universal.jar

I've got some of these elements in my PHP Array and I need to extract all except:

-1.7.10-1.0.5.110-universal.jar

So I tried to use regular expression like this:

/[\d\-|\.]*\.jar/

But it extracts modname only from string like this Example2-0.8.0.jar.

So I need to make it more flexible.

  • 写回答

1条回答 默认 最新

  • doutian3269 2015-07-02 06:11
    关注

    If I understand it correctly, you want to match every filename except the one containing 'universal'. To do so, you can use negative lookbehind with a pattern like this:

    /[\w\d\-|\._ ]*(?:(?<!universal)(\.jar)|(\.litemod))/
    

    DEMO: https://regex101.com/r/mI2fM8/3


    In case you just want to match the name (without version number, ...) something like this should be enough:

    /^[^\- ]+/
    

    DEMO: https://regex101.com/r/mI2fM8/5

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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据