Notepad++ 正则表达式查找 &替换换行符 [英] Notepad++ Regular Expression Find & Replace Across New Line Characters
问题描述
我正在尝试将文件中的一堆文本转换为可以放入 CSV 文件的格式.我试图通过提出一个可以进行转换的正则表达式来使用 Notepad++ 来做到这一点.我有以下格式的文本文件:
公司名称 1第一名:莎莉最后:科恩公司名称 2第一名:詹妮最后:史密斯第一位:约翰最后:面团
有些字段没有公司名称,但我正在尝试将其转换为以下格式:更换:
"公司名称 1";"Sally";"Cohen"公司名称 2";Janny";Smith""";"约翰";"面团"
Notepad++ 中搜索和替换字段的正确正则表达式组合是什么,以便跨新行执行此操作?
感谢您的帮助!
Regex
求什么:(?:\r\n)*(.*)\r\n第一个:(.+)\r\n最后一个:(.+)\r\n
>
替换为:"\1";"\2";"\3"\r\n
结果
详情
(?:\r\n)*
:匹配但不分组,删除公司名称或名字前的\r\n
(.*)\r\n
:匹配公司名称,.*
表示可以为空First: (.+)\r\n
andLast: (.+)\r\n
: 只匹配名字和姓氏,.+
表示它应该是至少一个字母
I'm trying to convert a bunch of text in a file into a format that can go into a CSV file. I'm trying to do this with Notepad++ by coming up with a regular expression that can do the conversions. 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:
"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?
Thank you for the help!
Regex
Find what: (?:\r\n)*(.*)\r\nFirst: (.+)\r\nLast: (.+)\r\n
Replace with: "\1";"\2";"\3"\r\n
Result
Detail
(?:\r\n)*
: match but not group, remove\r\n
before Company name or First(.*)\r\n
: match company name,.*
means it can be emptyFirst: (.+)\r\n
andLast: (.+)\r\n
: just match the first name and last name,.+
means it should be least one letter
这篇关于Notepad++ 正则表达式查找 &替换换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!