How to find "~" and replace with CR LF
Anthony Doshi last edited by
Newbie Question -
I have 1 text file.
I want to insert a Carriage Return(CR) and Line Feed(LF) after every tilde (“~”).
How can I accomplish this?
Terry R last edited by
this is a fairly simple regular expression. I would have hoped you might have done some research and seen the method, or at least provided us with something you tried, even if it didn’t work as expected. But being in the Xmas spirirt I will provide you with the solution.
So simply we look for the tilde
~, then the replace statement says put back what we just found, i.e. the tilde and append the carriage return and line feed.
This is a regular expression (regex) so the replace function needs to have the search mode as “regular expression” and wrap around should be ticked. Use the replace all button and in 1 step ALL tilde’s are appended by the new line.
PeterJones last edited by PeterJones
@Terry-R answered your immediate question, but if you have further search-and-replace (regex) needs, you can study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting the data so that the forum doesn’t mangle it (so that it shows “exactly”, as I said earlier), see this help-with-markdown post, where @Scott-Sumner gives a great summary of how to use Markdown for this forum’s needs.
Please note that for all “regex” queries – or queries where you want help “matching” or “marking” or “bookmarking” a certain pattern, which amounts to the same thing – it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.