简体   繁体   中英

How to exclude some word in string in regex (to replace using javascript)

I want to select word between two (") and exclude other word outside (") to replace string using javascript replace. This is my string

The receptionist: "Okay, please wait a moment." After a while, the receptionist smiled and said, "Congratulations, you have obtained a certificate of exemption from the exam for job transfer. With it, you can use it after you reach a certain Level. After completing the job transfer task, you can directly transfer to a specific occupation, a very convenient little gift."

I want to select "Okay, please wait a moment." and "Congratulations, you have obtained a certificate of exemption from the exam for job transfer. With it, you can use it after you reach a certain Level. After completing the job transfer task, you can directly transfer to a specific occupation, a very convenient little gift." and exclude other.

I try /".+"/g and it include all from "okay to gift." and not exclude other Please help me and thank you

I Think its could works: /("[^"]+")/g

This regexp match any group of words that have an initial " , one or more characters different to " and finally ends with a " You can see it in this regex101 image正则表达式的结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM