Results 1 to 4 of 4

Thread: Regex , find match and get text just before the next match

Threaded View

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Resolved 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
  •  



Click Here to Expand Forum to Full Width