Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hello,
I have a text which is formatted like this:
1- John (went-goes-go-gone) to school every day.
I need this to have the look of mutiple choice like this:
1. John ...... to school everyday.
a. went
b. goes
c. go
d. gone


can you help me with that, please?
Posted
Comments
Sergey Alexandrovich Kryukov 14-Nov-14 16:26pm    
Not clear. This is has nothing to do with "formatting". If this is related to natural language processing, natural language grammar and syntax, it looks like, it looks like, looking at regex is just not serious.
—SA
PIEBALDconsult 14-Nov-14 16:45pm    
Possibly. But I don't have time to think about it at the moment. Interesting puzzle, though.
Hamdi Sultan 14-Nov-14 16:51pm    
Thank you for your interest. I wish you could help me D:
Nelek 14-Nov-14 17:30pm    
Are all the lines following that structure?
I mean always (word1-word2-word3-word4) ???
Hamdi Sultan 15-Nov-14 12:32pm    
yes.

1 solution

If there are always four options in that format...

Pattern: ^([^(]+)\(([^-]+)-([^-]+)-([^-]+)-([^)]+)\)(.*)$
Replace: $1 ____ $6 \r\na. $2 \r\nb. $3 \r\nc. $4 \r\nd. $5

Input: 1. John (went-goes-go-gone) to school every day.

Result:
1. John  ____  to school every day. 
a. went 
b. goes 
c. go 
d. gone
 
Share this answer
 
v3
Comments
Matt T Heffron 14-Nov-14 19:56pm    
+5.
Interesting problem.
It looks like it is formatting a multiple choice test.
In this example, both a and b are correct!
Hamdi Sultan 15-Nov-14 12:45pm    
solution 2 by :PIEBALD works fine with the first row (sentence) . However, I have ten sentences in the original format. the regex did not make the changes to the rest of the nine sentences. thanks for help.
Nelek 15-Nov-14 13:20pm    
Are you sure they really are the same format?
PIEBALDconsult 15-Nov-14 14:05pm    
Try the Multiline option.

http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions(v=vs.110).aspx
Hamdi Sultan 16-Nov-14 10:10am    
PIEBALDconsult: thank you very much for your help. I fixed the problem. using the regex above. when I click the replace option in notepad++ there is an option to check or uncheck "matches newline" I uncheked it and it worked line by line. thanks for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900