• xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!


    js replace all

    https://stackoverflow.com/questions/1144783/how-can-i-replace-all-occurrences-of-a-string

    bug

    `133,456, 789`.replace(`,`,`,`);
    // "133,456, 789"
    
    `133,456, 133,456, 789`.replace(`,`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/ig`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/ig`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`//,/g`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/ug`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/ug`,`,`);
    // "133,456, 133,456, 789"
    
    
    `133,456, 133,456, 789`.replace(`/[u2018]/ug`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/u2018/ug`,`,`);
    // "133,456, 133,456, 789"
    
    
    `133,456, 133,456, 789`.replace(`/p{P}/g`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/[u3002|uff1f|uff01|uff0c|u3001|uff1b|uff1a|u201c|u201d|u2018|u2019|uff08|uff09|u300a|u300b|u3008|u3009|u3010|u3011|u300e|u300f|u300c|u300d|ufe43|ufe44|u3014|u3015|u2026|u2014|uff5e|ufe4f|uffe5]/g`,`,`);
    
    // "133,456, 133,456, 789"
    
    

    solutions

    regex & /regex /ig

    `133,456, 133,456, 789`.replace(/(p{Script=Hani})+/gu,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(/,/ig,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/ig`,`,`);
    // "133,456, 133,456, 789"
    
    
    
    
    `133,456, 133,456, 789`.replace(/[u3002|uff1f|uff01|uff0c|u3001|uff1b|uff1a|u201c|u201d|u2018|u2019|uff08|uff09|u300a|u300b|u3008|u3009|u3010|u3011|u300e|u300f|u300c|u300d|ufe43|ufe44|u3014|u3015|u2026|u2014|uff5e|ufe4f|uffe5]/g,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(/[u3002|uff1f|uff01|uff0c|u3001|uff1b|uff1a|u201c|u201d|u2018|u2019|uff08|uff09|u300a|u300b|u3008|u3009|u3010|u3011|u300e|u300f|u300c|u300d|ufe43|ufe44|u3014|u3015|u2026|u2014|uff5e|ufe4f|uffe5]/ug,`,`);
    // "133,456, 133,456, 789"
    
    

    Unicode

    https://stackoverflow.com/questions/44669073/regular-expression-to-match-and-split-on-chinese-comma-in-javascript

    split(/s*[,,]s*/)

    `133,456, 133,456, 789`.replace(`/,/ig`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/s*[,,]s*/ig`,`,`);
    // "133,456, 133,456, 789"
    
    
    
    `133,456, 133,456, 789`.split(/s*[,,]s*/);
    // ["133", "456", "133", "456", "789"]
    
    
    
    
    const  str = "继续,取消   继续 ,取消";
    console.log(str.split(/s*[,,]s*/));
    //  ["继续", "取消   继续", "取消"]
    
    

    Chinese comma

    how to replace all Chinese comma using regex in js

    https://en.wikipedia.org/wiki/Comma

    
    /s*(?:uD805uDC4D|uD836uDE87|[u002Cu02BBu060Cu2E32u2E34u2E41u2E49u3001uFE10uFE11uFE50uFE51uFF0CuFF64u00B7u055Du07F8u1363u1802u1808uA4FEuA60DuA6F5u02BDu0312u0313u0314u0315u0326u201A])s*/
    
    

    array flat

    
    `133,456, 133,456, 789`.replace(`/,/ig`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`,`,`,`);
    // "133,456, 133,456, 789"
    
    `133,456, 133,456, 789`.replace(`/,/g`,`,`);
    // "133,456, 133,456, 789"
    
    "133,456, 133,456, 789".split(`,`).split(`,`);
    // Uncaught TypeError:
    
    (anonymous) @ VM265:1
    "133,456, 133,456, 789".split(`,`);
    // ["133,456", " 133,456", " 789"]
    
    "133,456, 133,456, 789".split(`,`).map(item => item.split(`,`));
    // [Array(2), Array(2), Array(1)]
    
    Array.flat("133,456, 133,456, 789".split(`,`).map(item => item.split(`,`)));
    //  Uncaught TypeError: Array.flat is not a function
    
    "133,456, 133,456, 789".split(`,`).map(item => item.split(`,`)).flat();
    
    // ["133", "456", " 133", "456", " 789"]
    
    

    https://www.cnblogs.com/xgqfrms/p/10954098.html


    Array flat(Infinity)

    replaceAll & non-global RegExp

    ncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument at String.replaceAll

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll

    
    let s = `A man, a plan, a canal: Panama`;
    
    // all === g
    s.replace(/[^0-9a-zA-Z]/g, ``);
    // "AmanaplanacanalPanama"
    
    // once
    s.replace(/[^0-9a-zA-Z]/, ``);
    // "Aman, a plan, a canal: Panama"
    
    // not set global
    s.replaceAll(/[^0-9a-zA-Z]/, ``);
    // Uncaught TypeError: String.prototype.replaceAll called with a non-global RegExp argument
    
    // global falg === g
    s.replaceAll(/[^0-9a-zA-Z]/g, ``);
    // "AmanaplanacanalPanama"
    
    

    https://leetcode.com/submissions/detail/368182883/



    Flag Counter

    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    数据验证及文件操作
    Leecode336
    Leecode335
    正式回归
    自定义按钮的实现 windows phone
    asp.net中保存更改数据
    asp.net中可以这样序列化
    Asp.net mvc 3 实现进度条上传思路[转]
    server.MapPath
    Path.Combine (合并两个路径字符串)方法的一些使用细节
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/12554643.html
Copyright © 2020-2023  润新知