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

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

  •  
  •   doubleflower · Dec 17, 2016 · 3389 views
    This topic created in 3617 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
    doubleflower
    OP
    Dec 17, 2016
    1
    自已解决了 (["'])(?:\\.|(?!\1).)*\1
    doubleflower
    doubleflower
    OP
    Dec 17, 2016
    3
    @ngn999 你这个有问题啊
    http://regexr.com/3et8e
    doubleflower
    doubleflower
    OP
    Dec 17, 2016
    4
    目前来说这个似乎可以:
    http://regexr.com/3et8h

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