regex to change formatting in texts

A swapping-ground for Regular Expression syntax

regex to change formatting in texts

Postby hamdi sultan » Tue Dec 02, 2014 7:47 pm

hello there,
I have several documents in which there are a lot of multiple choice questions like the following:
Code: Select all
1- John ......... to school every day.
a) go       b) goes        c) went        d) gone

P.S the spaces between the four choices are not regular.
What I need is to change the format to be like this:
Code: Select all
1. John _____ to school every day.
a. go
b. goes
c. went
d. gone

Of course I can do this manually but it will take a lot of time. So can anyone help me , please?
hamdi sultan
 
Posts: 1
Joined: Tue Dec 02, 2014 7:36 pm

Re: regex to change formatting in texts

Postby Admin » Tue Dec 09, 2014 2:59 am

Hi, BulkRenameUtility can rename files (change the file name) but not text within the files, sorry.
Admin
Site Admin
 
Posts: 1504
Joined: Tue Mar 08, 2005 8:39 pm

Re: regex to change formatting in texts

Postby TheRegExpMaster » Tue Dec 09, 2014 10:13 pm

Hi Hamdi Sultan, like Admin said, you cannot change text within files. You must use a text editor that supports Regex Search&Replace within files like UltraEdit or make a script.

This should work in UltraEdit (Perl Regex only) if there are more than 4 points to replace with "_____" and if there are exactly 4 choices (a to d) :

MATCH :
Code: Select all
^(\d+)-(.+?)\.{4,}(.+?)\na\)(.+)\s+b\)(.+)\s+c\)(.+)\s+d\)(.+)\s*$

REPLACE :
Code: Select all
\1.\2_____\3\na.\4\nb.\5\nc.\6\nd.\7
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm


Return to Regular Expressions