New user registration is currently disabled due to spam abuse / Регистрация новых пользователей в настоящее время приостановлена из-за злоупотреблений спаммерами

Help with using regex

General discussion

Help with using regex

Postby midoziad » Thu Nov 13, 2014 7:25 pm

Hello there,
I have some documents where the formatting is like that:
The biggest ocean in the world (the Pacific-the Indian-the Atlantic-the south pole)

I want the above mentioned example to be like that:
The biggest ocean in the world is ......
a. the pacific
b. the Indian
c. the Atlantic
d. the south pole

If there is any way to use regex in notepad++ to do this task in the replace dialogue box.
thanks in advance
midoziad
 
Posts: 17
Joined: Sun Dec 30, 2012 6:14 pm

Re: Help with using regex

Postby C2BlEv » Thu Dec 04, 2014 5:49 pm

First, I use emeditor (not notepad++), so my regex may not work for you but who knows.
Second, can I assume that you only have four options in all cases (i.e. only a. b. c. d.)?
Third, can I assume there is no text after closing ")" at the end of your example in all cases?
If so, then

Turn regex on
Search: ^(.+?)\((.+?)\-(.+?)\-(.+?)\-(.+?)\)
Replace: \1is ......\na. \2\nb. \3\nc. \4\nd. \5
C2BlEv
Модератор
 
Posts: 215
Joined: Tue May 05, 2009 3:45 pm

Re: Help with using regex

Postby midoziad » Thu Dec 04, 2014 6:34 pm

Thank you for your response. I really appreciate it. Unluckily it didn't work for me properly.I think because in some sentences there are words after the ")" last parenthesis. Anyway I'd like to seek your help with a bit easier format:
Code: Select all
1- John ......... to school every day.
a) go        b) goes         c) went         d) gone

I want it to be like that:
Code: Select all
1. John ______ to school every day.
a. go
b. goes
c. went
d. gone

P.S the space between the four choices is either tabs or irregular spaces.
Please, help me with this problem as it will save me a lot of time and efforts
midoziad
 
Posts: 17
Joined: Sun Dec 30, 2012 6:14 pm

Re: Help with using regex

Postby C2BlEv » Thu Dec 04, 2014 7:00 pm

midoziad wrote:Unluckily it didn't work for me properly.I think because in some sentences there are words after the ")" last parenthesis.


In that case (if you have text after the closing paren), try the following:

Turn regex on
Search: ^(.+?)\((.+?)\-(.+?)\-(.+?)\-(.+?)\)(.+)$
Replace: \1is ......\na. \2\nb. \3\nc. \4\nd. \5\n\6

Note that you can put this extra text (i.e. \6) anywhere you want. For example,
Replace: \1\6 is ......\na. \2\nb. \3\nc. \4\nd. \5

midoziad wrote:Anyway I'd like to seek your help with a bit easier format:

Try this:

Turn regex on
Search: ^(\d+)\- (.+?) *?\.+ *?(.+)\na\) (.+?)[\t ]+b\) (.+?)[\t ]+c\) (.+?)[\t ]+d\) (.+?)$
Replace: \1. \2 _____ \3\na. \4\nb. \5\nc. \6\nd. \7

NOTE: I have not tested it so there might be slight issues to debug.
Also I assume that choices are always and only a, b, c, d. If not let me know and I'll adjust the regex.
C2BlEv
Модератор
 
Posts: 215
Joined: Tue May 05, 2009 3:45 pm

Re: Help with using regex

Postby midoziad » Fri Dec 05, 2014 7:56 pm

Hi
Thank you for your help. this regex was fantastic
^(.+?)\((.+?)\-(.+?)\-(.+?)\-(.+?)\)(.+)$
. However I made a modification to the replace thread to be like this:
Code: Select all
\1..........\6\na. \2\nb. \3\nc. \4\nd. \5

this means that the first part of the sentence "\1" is followed by dots space and then the second part of the sentence "\6". and it worked perfectly.
the second format didn't work .but I managed to make a regex as follows:
Code: Select all
^a\)\s(.*)\t+b\)\s(.*)\t+c\)\s(.*)\t+d\)\s(.*)

the replace is :
Code: Select all
a. $1 \r\nb. $2 \r\nc. $3 \r\nd. $4

Once again thank you very much. :D
midoziad
 
Posts: 17
Joined: Sun Dec 30, 2012 6:14 pm


Return to General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 25 guests