Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > regexp which matches nothing?

Reply
Thread Tools

regexp which matches nothing?

 
 
Joao Silva
Guest
Posts: n/a
 
      08-27-2009
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/.

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      08-27-2009
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/.

 
Reply With Quote
 
 
 
 
Kilian Verhetsel
Guest
Posts: n/a
 
      08-27-2009
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/.

 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      08-27-2009
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/.

 
Reply With Quote
 
Ralf Mueller
Guest
Posts: n/a
 
      08-27-2009
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'
 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      08-27-2009
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/.

 
Reply With Quote
 
Ralf Mueller
Guest
Posts: n/a
 
      08-27-2009
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replace random matches of regexp gry Python 4 09-08-2011 09:19 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
[Regexp] Howto capture all matches of a single group ersin.er@gmail.com Java 3 10-03-2005 10:11 AM
multiple regexp matches Kevin Howe Ruby 27 08-24-2004 02:30 PM
Please help with regexp - finding all matches? Boris Pelakh Perl 3 04-08-2004 08:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57