[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regex for whitespace plus vertical bar

Robert La ferla

7/28/2006 8:57:00 PM

I am trying to quote arguments that have whitespace or a pipe (vertical
bar character = | ) in them. Why doesn't this work? What does work?



if arg.index(/[\s|]/)
...

end

--
Posted via http://www.ruby-....

4 Answers

dblack

7/28/2006 9:02:00 PM

0

Matthew Smillie

7/28/2006 9:05:00 PM

0

On Jul 28, 2006, at 21:56, Robert La ferla wrote:

> I am trying to quote arguments that have whitespace or a pipe
> (vertical
> bar character = | ) in them. Why doesn't this work? What does work?
>
>
>
> if arg.index(/[\s|]/)

| is a reserved character in regexes for disjunction, i.e. /a|b/
matches a or b, where a and b are arbitrary regexes.

This ought to work for your purposes, I think:

if arg.index(/[\s\|]/)

matthew smillie.

Jason Sweat

7/28/2006 9:06:00 PM

0

On 7/28/06, Robert La ferla <robertlaferla@comcast.net> wrote:
> I am trying to quote arguments that have whitespace or a pipe (vertical
> bar character = | ) in them. Why doesn't this work? What does work?
>
>
>
> if arg.index(/[\s|]/)
> ...
>
> end

Seems to work for me:

$ irb
>> re=/[\s|]/
=> /[\s|]/
>> re.match('kldfslkd')
=> nil
>> re.match('df |sdf')
=> #<MatchData:0x4098995c>


Regards,
Jason
http://blog.casey...

William James

7/28/2006 11:19:00 PM

0

Matthew Smillie wrote:
> On Jul 28, 2006, at 21:56, Robert La ferla wrote:
>
> > I am trying to quote arguments that have whitespace or a pipe
> > (vertical
> > bar character = | ) in them. Why doesn't this work? What does work?
> >
> >
> >
> > if arg.index(/[\s|]/)
>
> | is a reserved character in regexes for disjunction,

Not in a character class.

>> "foo|bar" =~ /[|]/
=> 3