简体   繁体   中英

Regexp group matching number

I am using regexp replacing in emacs to replace the first term and third term's double quote to single quote. Input:
"term1" "term2" "term3" "term4"
(the term seperator is tab)

wanted output:
'term1' "term2" 'term3' "term4"

I used below regexp search and replacement strings:
search: "\\(.+?\\)" "\\(.+?\\)" "\\(.+?\\)"

replacement: '\\1' "\\2" '\\3'

However, the actual output replaces first and fourth term instead:
'term1' "term2" "term3" 'term4'

Is there any mistake in my regexp?

Elisp regexps are greedy, so I expect your first group is actually matching the whole line, not just the "term ". Try this instead:

"\([^"]+?\)" "\([^"]+?\)" "\([^"]+?\)"

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