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

求个正则表达式....周围实在没人.所以发这里了.

  •  
  •   firhome · Sep 12, 2013 · 3569 views
    This topic created in 4807 days ago, the information mentioned may be changed or developed.
    这就是单干的痛苦阿...

    'A1 A2 A3 A4 5A 66' 想变成 "1 2 3 4 5A 66"

    javascript里有办法一次正则去掉 数字在后的A,然而数字在前的A不去掉?
    11 replies  •  1970-01-01 08:00:00 +08:00
    qinxg
    qinxg
    Sep 12, 2013
    1
    [^A]
    felix021
    felix021
    Sep 12, 2013❤️1
    2
    正则入门不是只要30分钟吗....痛苦在哪?
    yushiro
    yushiro
    Sep 12, 2013❤️1
    3
    chrome 的console模式下运行:
    'A1 A2 A3 A4 5A 66'.replace(/A([0-9])/g,'$1')
    123123
    123123
    Sep 12, 2013
    4
    @yushiro 用\d多好非打那么多字
    yushiro
    yushiro
    Sep 12, 2013
    5
    @123123 被editplus折腾的,因为在editplus里面不支持\d, 还有好多操作都不支持。。。。。。所以习惯用0-9这种了=_=#
    Mutoo
    Mutoo
    Sep 12, 2013❤️1
    6
    可以用零宽断言,找到后面的数字的A
    "A1 A2 A3 A4 5A 66".replace(/A(?=\d)/g,"")
    yakczh
    yakczh
    Sep 12, 2013❤️1
    7
    <script>
    var a='A1 A2 A3 A4 5A 66' ;


    a=a.replace(/A(\d\s)/g,"$1");

    //alert(a);

    document.write(a);
    </script>
    solos
    solos
    Sep 12, 2013❤️1
    8
    可以用环视,'A1 A2 A3 A4 5A 66'.replace(/(?=A\d)A/g, '')
    Ever
    Ever
    Sep 12, 2013❤️1
    9
    'A1 A2 A3 A4 5A 66'.replace(/\bA/g,'')
    Alexisused
    Alexisused
    Sep 12, 2013❤️1
    10
    'A1 A2 A3 A4 5A 66'.replace(/A(\d)/g, '$1')
    yyife
    yyife
    Sep 12, 2013❤️1
    11
    var s = 'A1 A2 A3 A4 5A 66' ;
    var reg = /A(\d+)/g;
    console.log(s.replace(reg,function(w){return w.substr(1,w.length);}));
    可以随意处理
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   941 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 20:03 · PVG 04:03 · LAX 12:03 · JFK 15:03
    ♥ Do have faith in what you're doing.