Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grabbing values between quotation marks and replacing it enclosed inside some command

I am sure this has been asked before, but I am not sure how to search for the exact case.

How do I use regex to search/replace for whatever is inside double quotes, such as:

"Sample text"

and replace it with:

\command{Sample text}

where "Sample text" can be anything.

like image 628
blackened Avatar asked Mar 25 '26 09:03

blackened


1 Answers

Depends what tool/language you're using, but in general:

Search: "(.*?)"
Replace: \\command{$1}

This works by capturing (in group 1) the text inside quotes and using a back reference to that group in the replacement.

Your tool/language may use backslash instead of dollar to indicate the group number, ie try \\command{\1} instead if the above doesn't work.

like image 114
Bohemian Avatar answered Mar 27 '26 19:03

Bohemian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!