新行上的正则表达式对关联 [英] Regex pair Associative on new lines

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

问题描述

我必须为批量文件重命名器设置一个配对列表.我可以使用 php 获取 dir1 和 dir2 的文件内容,但在将其发送到批量重命名器之前,我需要将它们配对.我的问题是即使在php中,两个文件的输出也是这种形式

I have to set up a pairing list for bulk file renamer. I can get the file contents of dir1 and dir2 with php but before I send it to the bulk renamer I need to have them paired. My problem is that even in php, the output of the two files is in this form

output 1

abc.jpg
def.jpg
fgh.jpg

output 2

_01.wmv
_02.wmv
_03.wmv

尝试为其执行正则表达式,删除新行并将它们全部放在一个字符串中,然后使用

Tried performing a regex for it , removing the new lines and putting them all in one string, then using

([a-zA-Z]+)(.jpg)(.+)(_[0-9]+\.wmv)

并替换为

\r\n\1\2\r\n\4\r\n\3

但是,输出 first->last 并且必须重复该过程.我知道我错过了一些东西.

However, that outputs first->last and the procedure has to be repeated. I know I`m missing something.

也许是一个起始 ^ 字符串或我不知道的其他运算符.请帮忙.谢谢

Maybe a starting ^ string or another operator I`m unaware of. Please do help. Thank you

编辑//

所需的输出是

abc.jpg _01.wmv
def.jpg _02.wmv
fgh.jpg _03.wmv

把它们放在一个字符串中,我的意思是删除所有新行,所以输出会像这样

And by putting them in one string, I mean removing all the new lines, so output would be like this

abc.jpgdef.jpgfgh.jpg_01.wmv_02.wmv_03.wmv

感谢您的反馈!

推荐答案

我认为您想要的是类似于 Unix 粘贴命令.

I think you are wanting something like the Unix paste command.

在 Notepad++ 中实现类似功能的一种方法是使用矩形区域复制和粘贴.在 Notepad++ 中,按住 Alt 键,将鼠标指针拖到文本的矩形区域上,松开 Alt 键.复制所选区域.单击文件中的其他位置或另一个文件并粘贴复制的文本.对于问题中的平局问题,我会选择一个文件的全部内容并将其粘贴到另一个文件中.

One way to achieve something similar in Notepad++ is to use a rectangular area copy and paste. In Notepad++ press and hold down the Alt key, drag the mouse pointer over a rectangular area of text, release the Alt key. Copy the selected area. Click somewhere else in the file, or in another file and paste in the copied text. For tie problem in the question I would make a rectangular selection of the entire contents of one file and paste it into the other file.

注意在复制和粘贴时矩形选择如何处理不同长度的线.我建议在尝试使用真实文件之前先尝试一些文本.

Be careful of how rectangular selections work with lines of different lengths when copying and pasting. I suggest experimenting with some text before trying with the real files.

这篇关于新行上的正则表达式对关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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