Find and Replace with newline in the replacement string

已回答

I seem to be unable to perform a simple regex find/replace.
I am attempting to add a copyright block (3 lines) to the top of all my java files and am using a regex find replace like this:

Find: ^^
Replace: /*\n (C) 2007 blah blah blah\n*/

Unfortunately the "\n" is not expanded to a newline character. I also tried with "
n" but same result. Is the find-replace regex broken or do I not know how to use it?

I am using 6.0.5 build 6180

1
Avatar
Permanently deleted user

I am also getting the string literal when attempting this, doesn't add a line break in webstorm either.

 

I tried selecting the regex option (which was hidden and tricky to find on 12" screen) but this led to not finding any matches. Any clues on what is happening?

0

Replacing with new lines and with Regex option is working fine for me:

Find in Path action:

Find in File action:


Please double check your regex pattern.

1
Avatar
Permanently deleted user

It only occurs in cases where I have a replacement search term involving something like ‘const db = pmongo(config...’ when an open bracket is introduced. Are you getting the same?

0

If you are using regex option be sure to escape (with '\') all special characters like grouping parentheses: '(' or ')', see https://www.regular-expressions.info/refcharacters.html

1
Avatar
Permanently deleted user

Thank you, this is helpful!

0

escaping (\\n) worked for me, thanks!

0

请先登录再写评论。