Regular express question

Discussion in 'Python' started by elca, Oct 31, 2009.

  1. elca

    elca Guest

    Hello,
    i have some text document to parse.
    sample text is such like follow
    in this document, i would like to extract such like
    SUBJECT = 'NETHERLANDS MUSIC EPA'
    CONTENT = 'Michael Buble performs in Amsterdam Canadian singer Michael Buble
    performs during a concert in Amsterdam, The Netherlands, 30 October 2009.
    Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK '

    if anyone help me,much appreciate

    "
    NETHERLANDS MUSIC EPA | 36 before
    Michael Buble performs in Amsterdam Canadian singer Michael Buble performs
    during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble
    released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK
    "
    --
    View this message in context: http://old.nabble.com/Regular-express-question-tp26139434p26139434.html
    Sent from the Python - python-list mailing list archive at Nabble.com.
    elca, Oct 31, 2009
    #1
    1. Advertising

  2. elca

    alex23 Guest

    On Oct 31, 12:48 pm, elca <> wrote:
    > Hello,
    > i have some text document to parse.
    > sample text is such like follow
    > in this document, i would like to extract such like
    > SUBJECT = 'NETHERLANDS MUSIC EPA'
    > CONTENT = 'Michael Buble performs in Amsterdam Canadian singer Michael Buble
    > performs during a concert in Amsterdam, The Netherlands, 30 October 2009.
    > Buble released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK '
    >
    > if anyone help me,much appreciate
    >
    > "
    > NETHERLANDS MUSIC EPA | 36 before
    > Michael Buble performs in Amsterdam Canadian singer Michael Buble performs
    > during a concert in Amsterdam, The Netherlands, 30 October 2009. Buble
    > released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK
    > "


    You really don't need regular expressions for this:

    >>> import os
    >>> eol = os.linesep
    >>> text = '''

    .... NETHERLANDS MUSIC EPA | 36 before
    .... Michael Buble performs in Amsterdam Canadian singer Michael Buble
    performs
    .... during a concert in Amsterdam, The Netherlands, 30 October 2009.
    Buble
    .... released his new album entitled 'Crazy Love'. EPA/OLAF KRAAK
    .... '''
    >>> text = text.strip() # remove eol markers
    >>> subject = text.split(' | ')[0]
    >>> content = ' '.join(text.split(eol)[1:])
    >>> subject

    'NETHERLANDS MUSIC EPA'
    >>> content

    "Michael Buble performs in Amsterdam Canadian singer Michael Buble
    performs during a concert in Amsterdam, The Netherlands, 30 October
    2009. Buble released his new album entitled 'Crazy Love'. EPA/OLAF
    KRAAK"
    alex23, Nov 2, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nick

    regular express replace?

    nick, Jun 5, 2004, in forum: Perl
    Replies:
    3
    Views:
    1,415
    mp3idiot
    Jun 13, 2004
  2. ad
    Replies:
    7
    Views:
    659
    Scott Allen
    Apr 11, 2005
  3. =?Utf-8?B?Q2FybCBNLg==?=
    Replies:
    4
    Views:
    2,470
    sivlookingforu
    Aug 7, 2006
  4. brooksr
    Replies:
    3
    Views:
    326
    Jon Paal
    Dec 24, 2006
  5. Jake Henderson

    Visual Web Developer 2005 Express and SQL 2005 Express

    Jake Henderson, Mar 10, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    214
    Jake Henderson
    Mar 10, 2006
Loading...

Share This Page