• 请不要在回答技术问题时复制粘贴 AI 生成的内容
doubleflower
V2EX  ›  程序员

请教这个正则表达式怎么改能达到效果? (关于搜索源代码文件里的字符串)

  •  
  •   doubleflower · Dec 17, 2016 · 3035 views
    This topic created in 3436 days ago, the information mentioned may be changed or developed.
    正则见:

    http://regexr.com/3et85

    我是要查找所有的字符串,不过发现[]里的引用似乎不起作用啊?
    12 replies    2016-12-19 14:23:08 +08:00
    doubleflower
        1
    doubleflower  
    OP
       Dec 17, 2016
    自已解决了 (["'])(?:\\.|(?!\1).)*\1
    ngn999
        2
    ngn999  
       Dec 17, 2016   ❤️ 1
    doubleflower
        3
    doubleflower  
    OP
       Dec 17, 2016
    @ngn999 你这个有问题啊
    http://regexr.com/3et8e
    doubleflower
        4
    doubleflower  
    OP
       Dec 17, 2016
    目前来说这个似乎可以:
    http://regexr.com/3et8h

    我正在想明白其中的道理。
    sagaxu
        5
    sagaxu  
       Dec 18, 2016
    @doubleflower 遇到\"转义字符就不行了
    doubleflower
        6
    doubleflower  
    OP
       Dec 18, 2016
    @sagaxu 哈哈源代码里不准用\",所以不考虑这个问题。(我想了下考虑进去也能做到,只是更复杂了)
    icris
        7
    icris  
       Dec 18, 2016   ❤️ 1
    (['"]).*?\1
    stormhouse
        8
    stormhouse  
       Dec 19, 2016
    您这是要做词法分析吗
    chnhyg
        9
    chnhyg  
       Dec 19, 2016
    (['"])([^\1]+?)\1
    chnhyg
        10
    chnhyg  
       Dec 19, 2016
    好像在中括号内不能用 \1 ,被转义了。
    icris
        11
    icris  
       Dec 19, 2016
    @icris
    (['"])(\\\1|.)*?\1
    加了个 \" 支持
    ares951753
        12
    ares951753  
       Dec 19, 2016
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1678 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 16:26 · PVG 00:26 · LAX 09:26 · JFK 12:26
    ♥ Do have faith in what you're doing.