regexp which matches nothing?

Discussion in 'Ruby' started by Joao Silva, Aug 27, 2009.

  1. Joao Silva

    Joao Silva Guest

    How i can construct regexp, which will always matches nothing?

    For example:

    "xxxxxxx".match /my_special_regexp/
    => should be ALWAYS nil
    --
    Posted via http://www.ruby-forum.com/.
    Joao Silva, Aug 27, 2009
    #1
    1. Advertising

  2. Joao Silva

    7stud -- Guest

    Joao Silva wrote:
    > How i can construct regexp, which will always matches nothing?
    >
    > For example:
    >
    > "xxxxxxx".match /my_special_regexp/
    > => should be ALWAYS nil


    How about:

    re = /$a^/

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Aug 27, 2009
    #2
    1. Advertising

  3. Why do you want to have a such regex ?

    Anyway, it seems that /^$a/ will never match with any string.

    "a".match /^$a/
    => nil
    "".match /^$a/
    => nil
    "a ".match /^$a/
    => nil
    --
    Posted via http://www.ruby-forum.com/.
    Kilian Verhetsel, Aug 27, 2009
    #3
  4. Joao Silva

    7stud -- Guest

    7stud -- wrote:
    > Joao Silva wrote:
    >> How i can construct regexp, which will always matches nothing?
    >>
    >> For example:
    >>
    >> "xxxxxxx".match /my_special_regexp/
    >> => should be ALWAYS nil

    >
    > How about:
    >
    > re = /$a^/


    I guess that could be made even simpler:

    re = /a^/

    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Aug 27, 2009
    #4
  5. Joao Silva

    Ralf Mueller Guest

    Joao Silva wrote:
    > How i can construct regexp, which will always matches nothing?
    >
    > For example:
    >
    > "xxxxxxx".match /my_special_regexp/
    > => should be ALWAYS nil

    not sure, but something that should always be nil .... what about the constant 'nil' ;)
    Ralf Mueller, Aug 27, 2009
    #5
  6. Joao Silva

    7stud -- Guest

    7stud -- wrote:
    > 7stud -- wrote:
    >> Joao Silva wrote:
    >>> How i can construct regexp, which will always matches nothing?
    >>>
    >>> For example:
    >>>
    >>> "xxxxxxx".match /my_special_regexp/
    >>> => should be ALWAYS nil

    >>
    >> How about:
    >>
    >> re = /$a^/

    >
    > I guess that could be made even simpler:
    >
    > re = /a^/


    ..and probably more efficient:

    re = /a\A/
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Aug 27, 2009
    #6
  7. Joao Silva

    Ralf Mueller Guest

    Joao Silva wrote:
    > How i can construct regexp, which will always matches nothing?
    >
    > For example:
    >
    > "xxxxxxx".match /my_special_regexp/
    > => should be ALWAYS nil


    Just out of curiosity: Why do you use a method call, when you expect a constant?
    Ralf Mueller, Aug 27, 2009
    #7
    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. Boris Pelakh
    Replies:
    3
    Views:
    461
    Purl Gurl
    Apr 8, 2004
  2. Replies:
    3
    Views:
    1,557
  3. Replies:
    3
    Views:
    2,463
  4. Joao Silva
    Replies:
    16
    Views:
    355
    7stud --
    Aug 21, 2009
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    451
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page