#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    How to create a Reg exp to this text?


    Hi,

    Someone can help me?

    I would like to create a regexp to get "class" definition of this text:

    Code:
    from django.db import models 
    
    class Poll(models.Model):  
         question = models.CharField(max_length=200) 
         pub_date = models.DateTimeField('date published') 
    
    class Choice(models.Model): 
         poll = models.ForeignKey(Poll) 
         choice = models.CharField(max_length=200) 
         votes = models.IntegerField()
    My regexp should find this:
    Code:
    class Poll(models.Model):  
         question = models.CharField(max_length=200) 
         pub_date = models.DateTimeField('date published')

    So far my regexp looks like this:
    Code:
    class (.*?)\(models\.Model\):[\n\t\r\s]+[\w\d\.]+[\s]*=[\s]*[\x20\d\w().=',]+
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0
    I didn't want to use () because I didn't want to create a new group in my regexp. But I found (?: ) and a solution:

    Code:
    class (.*?)\(models\.Model\):(?:[\s]+[\w\d\.]+[\s]*=[\s]*[\x20\d\w().=',]+)+

IMN logo majestic logo threadwatch logo seochat tools logo