问题
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)
and replacing with
\r\n\1\2\r\n\4\r\n\3
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
EDIT//
The desired output is
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
Thank you for the feedback!
回答1:
I am not quite sure what you mean, but this is what I understand from your question: you have two files. Both of which contain some jpg and wmv filenames. You want to extract all these filenames from these two files. If so, this is what you need:
/(?:^|\G).*?([\w_]+\.(?:jpg|wmv))/sg
See it in action.
This regex uses \G and the /g modifier to make this regex repeat itself. How this works is very nicely explained over here.
回答2:
I think you are wanting something like the Unix paste command.
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.
来源:https://stackoverflow.com/questions/19099729/regex-pair-associative-on-new-lines