problem with regexp?

Discussion in 'Ruby' started by Wmute, Feb 3, 2006.

  1. Wmute

    Wmute Guest

    Hello,

    I am trying to replace some old Perl scripts with Ruby, however

    i get stuck with this line

    >>


    if line =~/($time)/ && line =~/(xxx)/

    <<
    $time is a global variable containing the current day/month, but it
    wont match!
    what am i doing wrong?


    I am new to Ruby, so please dont be offended.
     
    Wmute, Feb 3, 2006
    #1
    1. Advertising

  2. Wmute wrote:

    >
    > if line =~/($time)/ && line =~/(xxx)/
    >


    >

    in Ruby $.. wont reference a variable like in perl, use #{...}


    if line =~ /#{time}/ && line =~ /(xxx)/ ....

    in case of /#{(time)}/ regexp will be compiled each time...

    so you may consider:

    r = /#{time}/ , or:
    r = Regexp.new(time)


    ....
    probably some loop
    ....

    if line =~ r && ...

    lopex
     
    Marcin Mielżyński, Feb 3, 2006
    #2
    1. Advertising

  3. Wmute

    Michael Ulm Guest

    Wmute wrote:

    > Hello,
    >
    > I am trying to replace some old Perl scripts with Ruby, however
    >
    > i get stuck with this line
    >
    >
    >
    > if line =~/($time)/ && line =~/(xxx)/


    You probably want

    if line =~ /#{$time}/ and line =~ /#{xxx}/

    (assuming there is a variable called xxx).

    HTH

    Michael

    --
    Michael Ulm
    R&D Team
    ISIS Information Systems Austria
    tel: +43 2236 27551-219, fax: +43 2236 21081
    e-mail:
    Visit our Website: www.isis-papyrus.com

    ---------------------------------------------------------------
    This e-mail is only intended for the recipient and not legally
    binding. Unauthorised use, publication, reproduction or
    disclosure of the content of this e-mail is not permitted.
    This email has been checked for known viruses, but ISIS accepts
    no responsibility for malicious or inappropriate content.
    ---------------------------------------------------------------
     
    Michael Ulm, Feb 3, 2006
    #3
  4. Wmute

    Wmute Guest

    Thanks! problem solved!
     
    Wmute, Feb 3, 2006
    #4
    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. Greg Hurrell
    Replies:
    4
    Views:
    163
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    490
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    363
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    192
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    181
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page