- AuthorPosts
- May 28, 2018 at 7:54 am #23272Sal JelParticipant
I hope you wouldn’t mind answering a question about regular expressions:
I want to do a FIND and MOVE from one place to another within the same file. This will apply to hundreds of files at once.
Example FIND from the text below: Cat1[changing text]Cat2 and MOVE after Dog1[changing text]Dog2
——————————
ORIGINAL FILE
Cat1[changing text]Cat2 [changing text]
Dog1[changing text]Dog2 [changing text]
Cow1[changing text]Cow2 [changing text]
—————————–
—————————-
MANIPULATED FILE
text text text
Dog1[changing text]Dog2Cat1[changing text]Cat2 text text text
Cow1[changing text]Cow2 text text text
————————
In other words, I’m trying to move the everything with comes between Cat1 and Cat2 to a different location within the same file. The new location in this case is immediately after Dog1…Dog2. Is there a regex which allows for that? Thank you so much.May 29, 2018 at 7:49 am #23275Yutaka EmuraKeymasterHello,
I would like to clarify your question in order to help you.
Is the “Cat1…” line always immediately above the “Dog1…” line?
If so, set the Use Regualr Expression option, and replace(Cat.*?Cat2.*?)\n(Dog1.*?Dog2.*?)\n
with
\2\1\n
If not, please figure out the maximum number of lines that exist between the “Cat1…” line and the “Dog1…” line. If it is 10 lines, you can replace:
(Cat.*?Cat2.*?)\n{1,10}(Dog1.*?Dog2.*?)\n
with
\2\1\n
and also go to the Advanced button in the Replace dialog box, and enter “10” to the “Additional Lines to Search for Regular Expressions” text box.
I hope this helps.
May 31, 2018 at 4:04 am #23284Sal JelParticipantThe code you provided here works like a charm, and that’s exactly what I needed because the text will have several lines between Cat1 and Dog1. You added the code (1,10) for the max of 10 lines. Is there a limit to how many lines it can search. (i.e 100 lines?). Thank you for the code you provided I really appreciate it.
(Cat.*?Cat2.*?)\n{1,10}(Dog1.*?Dog2.*?)\n with \2\1\n
May 31, 2018 at 8:13 am #23288Yutaka EmuraKeymasterI looked at both Boost.Regex and Onigmo syntax specs, but I couldn’t find information regarding the maximum number you can specify in {n,m}. However, EmEditor has the limit of 10,000 you can specify in the “Additional Lines to Search for Regular Expressions” text box. Please note that the larger you specify, the slower EmEditor becomes.
- AuthorPosts
- You must be logged in to reply to this topic.