|
-
Jan 2nd, 2009, 02:03 PM
#1
Thread Starter
Sleep mode
Regex , find match and get text just before the next match
Say i have this text (from dictionary) :
knife n 1: edge tool used as a cutting instrument; has a pointed blade with a sharp edge and a handle 2: a weapon with a handle and blade with a sharp point 31: any long thin projection that is transient; "tongues of flame licked at the walls"; "rifles exploded quick knives of fire into the dark" [syn: {tongue}] v : use a knife on; "The victim was knifed to death" [syn: {stab}] [also: {knives} (pl)] .
I want to use regex to be able to put every definition on new line . Like so :
knife n
1: edge tool used as a cutting instrument; has a pointed blade with a sharp edge and a handle
2: a weapon with a handle and blade with a sharp point
3: any long thin projection that is transient; "tongues of flame licked at the walls"; "rifles exploded quick knives of fire into the dark" [syn: {tongue}] v : use a knife on; "The victim was knifed to death" [syn: {stab}] [also: {knives} (pl)]
I used this pattern "\s[1-9]+\x3A\s" to find number of definitions but i don't know how to select the match " n: " along with the word definition (just exactly before the second match occurs).
Any regex guru ?
Last edited by Pirate; Jan 4th, 2009 at 04:50 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|