Add characters to the end of a string using regex notepad2

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-05 09:30:34

问题


I have a massive string (a SQL query..) that I have written out in notepad2. I'm using Java, and I was just wondering if there was a fast and easy way to add something to the end of each line? For example:

String query = "" 
+ " select column1
+ " , column2
+ " , column3
+ " from table
);
//want to add \n" at the end of each line

回答1:


Find: (.)$
Replace: \1\\n"

Here's a good regex tutorial.




回答2:


Maybe something like this

  1. ctrl + H
  2. mark regular expressions option
  3. search for $ - this means "end of line"
  4. replace with \\n"

OR simpler

  1. select lines that you want to edit
  2. alt + M / same as edit->block->modify lines
  3. in append text to lines place \n"



回答3:


For anyone still here 5 years later, and you are attempting to add something onto the end a line for a large non-code file (and don't want to use REGEX), there are helpful online converter tools like https://pinetools.com/add-text-each-line.

Helped me out a bunch for creating CSV files for a neural network I was making




回答4:


ctrl+h

make sure regex is on.

find: (.)\r\n

replace: \1 + "\\\n"\r\n



回答5:


In Regex you can group expressions using () - Parenthesis, and represent them as \1, \2, etc. So, anything like this can be appended as follows:

Find: (.*); Replace: \1 your_new_text ;



来源:https://stackoverflow.com/questions/17553390/add-characters-to-the-end-of-a-string-using-regex-notepad2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!