Javascript Regex - Quotes to Parenthesis

后端 未结 2 581
孤独总比滥情好
孤独总比滥情好 2021-01-27 02:47

I\'d like to somehow replace the string sequence \"*\" with (*) using a regex in Javascript. Replacing things between quotes to be between opening and closing parenthesis.

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 03:02

    You could try something like

    replace(/"(.*?)"/g, "($1)")
    

    Example

    "this will be \"replaced\"".replace(/"(.*)"/, "($1)")
    => this will be (replaced)
    
    "this \"this\" will be \"replaced\"".replace(/"(.*?)"/g, "($1)")
    => this (this) will be (replaced)
    

提交回复
热议问题