Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用该replace函数使用正则表达式向 JavaScript 中的每一行添加单个字符?
replace
使用行首正则表达式:
// X is the single char to add: str = str.replace(/^/gm, "X");
标志导致跨行gm匹配。
gm