![](/img/trans.png)
[英]What is this capture group doing in this regex expression in the replace function documentation in Javascript?
[英]Regex interpretation and javascript's replace function. Why do we need the capture group?
var cleaned_input = input.replace(/(\s{2,}\n|\t)/g," ")
我有這條線。 這個正則表達式似乎只用一個空格就可以替換兩個或兩個以上空格,任何換行符和所有制表符。 但是為什么我需要捕獲組? 捕獲了什么?
此正則表達式確實用單個空格代替所有“連續空格(2個或更多),然后是換行”或“各個制表符”。
在這種情況下,捕獲組不是必需的,但我認為它是放置在這里的,因為錯誤的假設,即(( |
)語句始終需要放在括號內。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.