Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to detect and replace double quoted strings ? Ex: "use strict"; #13

Open
cbdeveloper opened this issue Nov 25, 2020 · 2 comments

Comments

@cbdeveloper
Copy link

I guess my issue is related to double quote strings.

index.js

"use strict";

// REST OF THE FILE

I need to add a require() after the "use strict";, so it will become:

"use strict";
require("module-alias/register");

// REST OF THE FILE

I'm trying to enclose the double quotes with single quotes:

npx replace-in-files --string='"use strict";' --replacement='"use strict";\nrequire("module-alias/register");'

Is it something possible to do?

@Ashlanfox
Copy link

You simply need to escape the double quote with a slash.

@j-catania
Copy link

Hi @cbdeveloper,

This is my case in package.json script working great :

"replace:config": "replace-in-files --regex='version=\\\"\\d+\\.\\d+\\.\\d+\\\"+' --replacement=version=\\\"$npm_package_version\\\" config.xml"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants