简体   繁体   English

Notepad ++正则表达式跨换行符查找和替换

[英]Notepad++ Regular Expression Find & Replace Across New Line Characters

I'm trying to convert a bunch of text in a file into a format that can go into a CSV file. 我正在尝试将文件中的一堆文本转换为可以转换为CSV文件的格式。 I'm trying to do this with Notepad++ by coming up with a regular expression that can do the conversions. 我正在尝试通过使用可进行转换的正则表达式来使用Notepad ++进行此操作。 I have a text file in the following format: 我有以下格式的文本文件:

Company Name 1
First: Sally
Last: Cohen

Company Name 2
First: Janny
Last: Smith

First: John
Last: Dough

Some fields don't have a company name, but I'm trying to convert it into the following format: REPLACEMENT: 某些字段没有公司名称,但是我正尝试将其转换为以下格式:REPLACEMENT:

"Company Name 1";"Sally";"Cohen"
"Company Name 2";"Janny";"Smith"
"";"John";"Dough"

What is the right regular expression combination for the search and replace fields in Notepad++ to do this across new lines? 在Notepad ++中搜索和替换字段能在新行中执行此操作的正确正则表达式组合是什么?

Thank you for the help! 感谢您的帮助!

Regex 正则表达式

Find what: (?:\\r\\n)*(.*)\\r\\nFirst: (.+)\\r\\nLast: (.+)\\r\\n 查找内容: (?:\\r\\n)*(.*)\\r\\nFirst: (.+)\\r\\nLast: (.+)\\r\\n

Replace with: "\\1";"\\2";"\\3"\\r\\n 替换为: "\\1";"\\2";"\\3"\\r\\n

Result 结果

在此处输入图片说明

Detail 详情

  1. (?:\\r\\n)* : match but not group, remove \\r\\n before Company name or First (?:\\r\\n)* :匹配但不分组,请在公司名称或“第一”前删除\\r\\n
  2. (.*)\\r\\n : match company name, .* means it can be empty (.*)\\r\\n :与公司名称匹配, .*表示可以为空
  3. First: (.+)\\r\\n and Last: (.+)\\r\\n : just match the first name and last name, .+ means it should be least one letter 名字First: (.+)\\r\\nLast: (.+)\\r\\n :仅与名字和姓氏匹配, .+表示应至少包含一个字母

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM