Which pattern represents any characters including space, \t \n?
···
--
Posted via http://www.ruby-forum.com/.
Which pattern represents any characters including space, \t \n?
--
Posted via http://www.ruby-forum.com/.
"Please read before posting
This forum is connected to a mailing list that is read by thousands of
people. Before you post, please use the FAQ, the Ruby documentation and
Google to find an answer to your question. If you can't find an answer
there, make sure to include all relevant information that is necessary
to help you in your post."
You should only post a doubt if you can't find the information you need,
not to have someone answer what you can find.
For your question's answer see this link.
http://www.rubyist.net/~slagell/ruby/regexp.html
Pedro.
--
Posted via http://www.ruby-forum.com/.
It's \s
On Mon, Sep 1, 2008 at 10:20 AM, Zhao Yi <youhaodeyi@gmail.com> wrote:
Which pattern represents any characters including space, \t \n?
Zhao Yi wrote:
Which pattern represents any characters including space, \t \n?
The pattern that matches any character is
/./m
The /m switches the Regexp into multiline mode, and then . matches also
\n.
TPR.
--
Posted via http://www.ruby-forum.com/\.
Thomas Wieczorek wrote:
> Which pattern represents any characters including space, \t \n?
It's \s
I think he actually wants /./m as he said "any character" and not "any
whitespace character".
HTH,
Sebastian
--
NP: Die Apokalyptischen Reiter - Es wird schlimmer
Jabber: sepp2k@jabber.org
ICQ: 205544826
Sebastian Hungerecker wrote:
Thomas Wieczorek wrote:
> Which pattern represents any characters including space, \t \n?
It's \s
I think he actually wants /./m as he said "any character" and not "any
whitespace character".HTH,
Sebastian
I think this is better [.\s]
--
Posted via http://www.ruby-forum.com/\.
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
--
NP: Tyr - Dreams
Jabber: sepp2k@jabber.org
ICQ: 205544826
Sebastian Hungerecker wrote:
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
Why? It should match any character.
--
Posted via http://www.ruby-forum.com/\.
Zhao Yi wrote:
Sebastian Hungerecker wrote:
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
Why? It should match any character.
From the docs, http://www.ruby-doc.org/docs/UsersGuide/rg/regexp.html
\s| space character; same as |[ \t\n\r\f]
That is not any character it is only whitespace.
Zhao Yi wrote:
Why? It should match any character.
Yes, but so does just . when you specify the m modifier. So why make it [.\s]
if you can just do . ?
--
NP: Disbelief - Death Will Score
Jabber: sepp2k@jabber.org
ICQ: 205544826
Generally, "." matches characters including what "\s" matches.
Save your presence, I think you'd better learn more basic regular
expression knowledge first.
Zhao Yi wrote:
Sebastian Hungerecker wrote:
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
Why? It should match any character.
Hi --
On Mon, 1 Sep 2008, Sebastian Hungerecker wrote:
Zhao Yi wrote:
Why? It should match any character.
Yes, but so does just . when you specify the m modifier. So why make it [.\s]
if you can just do . ?
It depends whether you want to use . without including \n somewhere
else in your regex, and therefore don't want the m modifier.
David
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
Hi --
On Mon, 1 Sep 2008, Peter Hickman wrote:
Zhao Yi wrote:
Sebastian Hungerecker wrote:
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
Why? It should match any character.
From the docs, http://www.ruby-doc.org/docs/UsersGuide/rg/regexp.html
>\s| space character; same as |[ \t\n\r\f]
That is not any character it is only whitespace.
Yes, but [.\s] is a character class, consisting of any character other
than \n, plus any space including \n. So it will match any character.
David
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
One reason would be that you need option /m which is effective for the
whole RX. You can avoid that by doing /(?m:.)/
Cheers
robert
2008/9/1 Sebastian Hungerecker <sepp2k@googlemail.com>:
Zhao Yi wrote:
Why? It should match any character.
Yes, but so does just . when you specify the m modifier. So why make it [.\s]
if you can just do . ?
--
use.inject do |as, often| as.you_can - without end
Hi --
On Mon, 1 Sep 2008, Patrick He wrote:
Generally, "." matches characters including what "\s" matches.
No, by default . does not match \n. You can make it do so with the /m
modifier.
David
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
Additionally, you can use pattern "(.|\n)" if you want to match all
characters including "\n" in single line mode.
Patrick He wrote:
Generally, "." matches characters including what "\s" matches.
Save your presence, I think you'd better learn more basic regular
expression knowledge first.Zhao Yi wrote:
Sebastian Hungerecker wrote:
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
Why? It should match any character.
David A. Black wrote:
It depends whether you want to use . without including \n somewhere
else in your regex, and therefore don't want the m modifier.
Good point.
--
Jabber: sepp2k@jabber.org
ICQ: 205544826
Yes, thank you for reminding me. ![]()
David A. Black wrote:
Hi --
On Mon, 1 Sep 2008, Patrick He wrote:
Generally, "." matches characters including what "\s" matches.
No, by default . does not match \n. You can make it do so with the /m
modifier.David
Hi --
Additionally, you can use pattern "(.|\n)" if you want to match all
characters including "\n" in single line mode.
Ruby regexes don't really have a single vs. multiple line mode
distinction. They always act as if they have the Perl /m modifier in
place, so that ^ and $ match beginning and end of line but never
beginning and end of string. So Ruby's default mode is like Perl's
multi-line mode. Ruby doesn't really have a single-line mode. /m just
adds \n to the . class, so it's sort of single line, but ^ and $ still
match lines and not the whole string.
David
On Mon, 1 Sep 2008, Patrick He wrote:
--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
Hi --
Zhao Yi wrote:
Sebastian Hungerecker wrote:
Zhao Yi wrote:
I think this is better [.\s]
No, it's not.
Why? It should match any character.
From the docs, http://www.ruby-doc.org/docs/UsersGuide/rg/regexp.html
>\s| space character; same as |[ \t\n\r\f]
That is not any character it is only whitespace.
Yes, but [.\s] is a character class, consisting of any character other
than \n, plus any space including \n. So it will match any character.
No, it's not:
>> "a" =~ /[.\n]/
=> nil
The period loses its special meaning inside a character class, so that class literally matches a period or a newline character.
James Edward Gray II
On Sep 1, 2008, at 4:27 AM, David A. Black wrote:
On Mon, 1 Sep 2008, Peter Hickman wrote: