Character classes use in Ruby

Can anyone help me by giving an explanatory example of each of the
below:

[:alnum:]

[:alpha:]

[:space:]

[:xdigit:]

[:punct:]

[:space:]

[:blank:]

Thanks

···

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

http://lmgtfy.com/?q=[%3Aalnum%3A]+%20[%3Aalpha%3A]+%20[%3Aspace%3A]+%20[%3Axdigit%3A]+%20[%3Apunct%3A]+%20[%3Aspace%3A]+%20[%3Ablank%3A]&l=1

···

On 4 February 2013 20:26, Love U Ruby <lists@ruby-forum.com> wrote:

Can anyone help me by giving an explanatory example of each of the
below:

[:alnum:]

[:alpha:]

[:space:]

[:xdigit:]

[:punct:]

[:space:]

[:blank:]

Thanks

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/
  ABN: 59-013-727-651

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

Hi,

aren't those names self-explanatory?

alnum = alphanumeric = a letter of any alphabet or a digit (a, Щ, 1,
...)
space = spaces, tabs, newlines, ...
xdigit = hexadecimal digit (a-zA-Z0-9)

etc.

···

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

my-ruby:
did you even try to google that list?
http://ruby-doc.org/core-1.9.3/Regexp.html

/[[:alnum:]]/ - Alphabetic and numeric character
/[[:alpha:]]/ - Alphabetic character
/[[:blank:]]/ - Space or tab
/[[:cntrl:]]/ - Control character
/[[:digit:]]/ - Digit
/[[:graph:]]/ - Non-blank character (excludes spaces, control
characters, and similar)
/[[:lower:]]/ - Lowercase alphabetical character
/[[:print:]]/ - Like [:graph:], but includes the space character
/[[:punct:]]/ - Punctuation character
/[[:space:]]/ - Whitespace character ([:blank:], newline, carriage
return, etc.)
/[[:upper:]]/ - Uppercase alphabetical
/[[:xdigit:]]/ - Digit allowed in a hexadecimal number (i.e., 0-9a-fA-F)

···

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

digit for sample can match more than just plain 0-9

# U+06F2 is "EXTENDED ARABIC-INDIC DIGIT TWO"
/[[:digit:]]/.match("\u06F2") #=> #<MatchData "\u{06F2}">

···

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

I'm sorry, but I *just* answered another post where my solution detailed
the steps I used to *search Google for the answer*, and I know for a fact
that this answer can be resolved easily and instantly with a 2 second
search.

I will try to be more like Matz in future. :blush:

···

On 4 February 2013 20:29, Matthew Kerwin <matthew@kerwin.net.au> wrote:

http://lmgtfy.com/?q=[%3Aalnum%3A]+%20[%3Aalpha%3A]+%20[%3Aspace%3A]+%20[%3Axdigit%3A]+%20[%3Apunct%3A]+%20[%3Aspace%3A]+%20[%3Ablank%3A]&l=1

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/
  ABN: 59-013-727-651

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

Hans Mackowiak wrote in post #1095104:

my-ruby:
did you even try to google that list?
Class: Regexp (Ruby 1.9.3)

/[[:alnum:]]/ - Alphabetic and numeric character
/[[:alpha:]]/ - Alphabetic character
/[[:blank:]]/ - Space or tab
/[[:cntrl:]]/ - Control character
/[[:digit:]]/ - Digit

I know their description - but would be good for me if I get a ruby tiny
code to see their uses. Mainly how syntactically are they
used,basically.

Thanks

···

--
Posted via http://www.ruby-forum.com/\.

Hans Mackowiak wrote in post #1095110:

digit for sample can match more than just plain 0-9

# U+06F2 is "EXTENDED ARABIC-INDIC DIGIT TWO"
/[[:digit:]]/.match("\u06F2") #=> #<MatchData "\u{06F2}">

Any example for the others as I listed in my description?

···

--
Posted via http://www.ruby-forum.com/\.

Read the page Hans pointed you to:

/[[:upper:]][[:lower:]]/.match("Hello") #=> #<MatchData "He">

···

On Mon, Feb 4, 2013 at 4:59 AM, Love U Ruby <lists@ruby-forum.com> wrote:

Hans Mackowiak wrote in post #1095104:

my-ruby:
did you even try to google that list?
http://ruby-doc.org/core-1.9.3/Regexp.html

/[[:alnum:]]/ - Alphabetic and numeric character
/[[:alpha:]]/ - Alphabetic character
/[[:blank:]]/ - Space or tab
/[[:cntrl:]]/ - Control character
/[[:digit:]]/ - Digit

I know their description - but would be good for me if I get a ruby tiny
code to see their uses. Mainly how syntactically are they
used,basically.

Love U Ruby wrote in post #1095145:

Hans Mackowiak wrote in post #1095110:

digit for sample can match more than just plain 0-9

# U+06F2 is "EXTENDED ARABIC-INDIC DIGIT TWO"
/[[:digit:]]/.match("\u06F2") #=> #<MatchData "\u{06F2}">

Any example for the others as I listed in my description?

You now know the syntax, try them in IRB to discover their behaviour.

···

--
Posted via http://www.ruby-forum.com/\.

tamouse mailing lists wrote in post #1095109:

···

On Mon, Feb 4, 2013 at 4:59 AM, Love U Ruby <lists@ruby-forum.com> > wrote:

/[[:digit:]]/ - Digit

I know their description - but would be good for me if I get a ruby tiny
code to see their uses. Mainly how syntactically are they
used,basically.

Read the page Hans pointed you to:

/[[:upper:]][[:lower:]]/.match("Hello") #=> #<MatchData "He">

Okay! Could you explain how the matching here performed, to produce
"#<MatchData "He">"

--
Posted via http://www.ruby-forum.com/\.

Could you at least at some point take 10 seconds and try to figure anything
out on your own? 99.9% of the fun of development is the excitement of
figuring something out. If all you are going to do every day is just
accomplish nothing then why bother with this path in life?

What possibly do you believe would produce that result? What about trying
with "hEllo" or "HELLO" or "hello" and see what comes back and see what you
can deduce from that. Then move on to something like "HeLlO" and see how it
works and what you can do to get multiple results and how to handle
multiple results.

You are missing so much of the enjoyment of the language by sitting there
and accomplishing absolutely nothing on your own.

···

On Mon, Feb 4, 2013 at 7:46 AM, Love U Ruby <lists@ruby-forum.com> wrote:

tamouse mailing lists wrote in post #1095109:
> On Mon, Feb 4, 2013 at 4:59 AM, Love U Ruby <lists@ruby-forum.com> > > wrote:
>>> /[[:digit:]]/ - Digit
>>
>> I know their description - but would be good for me if I get a ruby tiny
>> code to see their uses. Mainly how syntactically are they
>> used,basically.
>
> Read the page Hans pointed you to:
>
> /[[:upper:]][[:lower:]]/.match("Hello") #=> #<MatchData "He">

Okay! Could you explain how the matching here performed, to produce
"#<MatchData "He">"

There are tutorials on regular expressions out there on the web.
Nobody is going to go through the effort to write another one just for
you.

If you want a book, read "Mastering Regular Expressions".

Cheers

robert

···

On Mon, Feb 4, 2013 at 4:46 PM, Love U Ruby <lists@ruby-forum.com> wrote:

tamouse mailing lists wrote in post #1095109:

On Mon, Feb 4, 2013 at 4:59 AM, Love U Ruby <lists@ruby-forum.com> >> wrote:

/[[:digit:]]/ - Digit

I know their description - but would be good for me if I get a ruby tiny
code to see their uses. Mainly how syntactically are they
used,basically.

Read the page Hans pointed you to:

/[[:upper:]][[:lower:]]/.match("Hello") #=> #<MatchData "He">

Okay! Could you explain how the matching here performed, to produce
"#<MatchData "He">"

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/