Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Lookaround problem

Last post 02-04-2010, 10:47 AM by arbiorix. 2 replies.
Sort Posts: Previous Next
  •  02-04-2010, 6:35 AM 59281

    Lookaround problem

    Hi,

    I cannot find out the regex expression that will do the following:

    For example, in " I have one blue car and you have two blue bikes", I need to extract the quantity text ('one' or 'two').

    But I only need the quantity for the item('car' or 'bikes') that I specify.
    Here is what I've tested so far (without succes!)

       1. regex = 'have.*blue.*(?<=car)' -> result = 'have one blue car' <-Ok
       2. regex = 'have.*blue.*(?<=bikes)' -> result = 'have one blue car and you have two blue bikes' <- NOk. I would expect 'have two blue bikes'

    Any idea about what I am missing?

  •  02-04-2010, 10:30 AM 59284 in reply to 59281

    Re: Lookaround problem

    have\s*?([a-zA-Z]+)\s*?blue\s*?(car|bikes)

    this will return you 2 matches:

     have one blue car

    have two blue bikes

    group 1will contain a numerical: one or two

    group 2 will containg the token : car or bikes

     

  •  02-04-2010, 10:47 AM 59285 in reply to 59284

    Re: Lookaround problem

    Sergei,

     

    Thank you for your response.

    It is exactly what I was looking for.

    Arbiorix

     

    Greetings from Brussels

View as RSS news feed in XML