Notepad++ 正则表达式查找 &替换换行符 [英] Notepad++ Regular Expression Find & Replace Across New Line Characters

查看:63
本文介绍了Notepad++ 正则表达式查找 &替换换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件中的一堆文本转换为可以放入 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

结果

详情

  1. (?:\r\n)*:匹配但不分组,删除公司名称或名字前的​​\r\n
  2. (.*)\r\n:匹配公司名称,.*表示可以为空
  3. First: (.+)\r\n and Last: (.+)\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

  1. (?:\r\n)*: match but not group, remove \r\n before Company name or First
  2. (.*)\r\n: match company name, .* means it can be empty
  3. First: (.+)\r\n and Last: (.+)\r\n: just match the first name and last name, .+ means it should be least one letter

这篇关于Notepad++ 正则表达式查找 &替换换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆