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

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

  •  
  •   firhome · Sep 12, 2013 · 3280 views
    This topic created in 4649 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
        1
    qinxg  
       Sep 12, 2013
    [^A]
    felix021
        2
    felix021  
       Sep 12, 2013   ❤️ 1
    正则入门不是只要30分钟吗....痛苦在哪?
    yushiro
        3
    yushiro  
       Sep 12, 2013   ❤️ 1
    chrome 的console模式下运行:
    'A1 A2 A3 A4 5A 66'.replace(/A([0-9])/g,'$1')
    123123
        4
    123123  
       Sep 12, 2013
    @yushiro 用\d多好非打那么多字
    yushiro
        5
    yushiro  
       Sep 12, 2013
    @123123 被editplus折腾的,因为在editplus里面不支持\d, 还有好多操作都不支持。。。。。。所以习惯用0-9这种了=_=#
    Mutoo
        6
    Mutoo  
       Sep 12, 2013   ❤️ 1
    可以用零宽断言,找到后面的数字的A
    "A1 A2 A3 A4 5A 66".replace(/A(?=\d)/g,"")
    yakczh
        7
    yakczh  
       Sep 12, 2013   ❤️ 1
    <script>
    var a='A1 A2 A3 A4 5A 66' ;


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

    //alert(a);

    document.write(a);
    </script>
    solos
        8
    solos  
       Sep 12, 2013   ❤️ 1
    可以用环视,'A1 A2 A3 A4 5A 66'.replace(/(?=A\d)A/g, '')
    Ever
        9
    Ever  
       Sep 12, 2013   ❤️ 1
    'A1 A2 A3 A4 5A 66'.replace(/\bA/g,'')
    Alexisused
        10
    Alexisused  
       Sep 12, 2013   ❤️ 1
    'A1 A2 A3 A4 5A 66'.replace(/A(\d)/g, '$1')
    yyife
        11
    yyife  
       Sep 12, 2013   ❤️ 1
    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   ·   Solana   ·   2745 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 11:45 · PVG 19:45 · LAX 04:45 · JFK 07:45
    ♥ Do have faith in what you're doing.