puts( /^[a-z 0-9]*$/ =~ ‘Well hello 123’ ) # no match due to ^ and
uppercase ‘W’
puts( /^[a-z 0-9]*/ =~ ‘Well hello 123’ ) # * zero (or more) matches at
start ^ = 0
i could barely understand why the existence of $ makes such a
difference.
any help?
puts( /[a-z 0-9]*$/ =~ ‘Well hello 123’ ) # no ^, so match made at char
1 ‘e’
puts( /[a-z 0-9]$/ =~ ‘Well hello 123’ ) # $ match from end = 13
so as this one,why does * makes such a difference?
i could barely understand why the existence of $ makes such a
difference.
any help?
/^[a-z 0-9]*$/ must match the whole string (and it can’t due to
uppercase ‘W’
/^[a-z 0-9]*/ may match only empty string at the beginning (and it does)
puts( /[a-z 0-9]$/ =~ ‘Well hello 123’ ) # $ match from end = 13
so as this one,why does * makes such a difference?
Without * regexp may match only one char at the end of the string.
On Sat, Nov 20, 2010 at 7:41 PM, Stanford Ng [email protected]
wrote:
–
Posted via http://www.ruby-forum.com/.
Why don’t you play with it at rubular.com for a while, it will help you
to
see easier what is happening when you change your regexp.
On Sun, Nov 21, 2010 at 7:59 AM, Stanford Ng [email protected]
wrote:
dudes,i am really confused with this.
could someone elaborate more on this?
/^\s*#/
–
Posted via http://www.ruby-forum.com/.
Could you elaborate on what has you confused? What do you expect it to
match? What text are you matching it against? What methods are using it
and
how are you calling them?
pal,i think i need more elaborate on these two expressions if possible.
/^[a-z]/
/[a-z]$/
please
i think i roughly understand by now.
thanks for your help
On 21.11.2010 15:11, Stanford Ng wrote:
pal,i think i need more elaborate on these two expressions if possible.
/^[a-z]/
/[a-z]$/
please
Please don’t write “need” and ask specific questions. It’s just too
broad a question you are posing here. People could write books in
answer to this. See also:
http://www.catb.org/~esr/faqs/smart-questions.html
Kind regards
robert
On Sun, Nov 21, 2010 at 4:11 PM, Stanford Ng [email protected]
wrote:
pal,i think i need more elaborate on these two expressions if possible.
/^[a-z]/
/[a-z]$/
please
This might help. The following two expressions are matching the same
thing:
‘Well hello 123’ =~ /^[a-z]*/
=> 0
‘Well hello 123’ =~ /^/
=> 0
Same here:
‘Well hello 123’ =~ /[a-z]*$/
=> 14
‘Well hello 123’ =~ /$/
=> 14
For more details, take a look at the matched data
/^[a-z]/.match(‘Well hello 123’).to_a
=> [“”]
/[a-z]$/.match(‘Well hello 123’).to_a
=> [“”]
HTH,
Ammar
Some time ago, I needed to buy a good car for my firm but I didn’t have
enough money and could not purchase anything. Thank goodness my friend
proposed to take the home loans at
trustworthy bank. Thence, I did so and used to be satisfied with my
commercial loan.