Skip to main content

take

- learnt that .take is different to that of .first. take returns it as an array while first returns as a sring if its the first object.
a = [1, 2, 3]
a.first 3 == a.take 3
a.first != a.take 1 #=> '1' != ['1']

- In Regex, ^ opens and $ closes if you want first character or last character regx
^a|a$ mean it has to start with a or end with a

Another and operator in regex for AND
https://stackoverflow.com/questions/6437516/how-to-use-and-in-ruby-regex
https://stackoverflow.com/questions/3041320/regex-and-operator


- Regex or operator
^ten.*|.*?end$

starts with ten or ends with end

- Learnt %r which is similar to having a / ... /

https://stackoverflow.com/questions/12384704/the-ruby-r-expression

- More on regex
https://stackoverflow.com/questions/8020848/and-or-operator-in-regular-expression

http://www.regular-expressions.info/

http://www.rexegg.com/regex-quickstart.html

- Ruby resource
http://ruby-for-beginners.rubymonstas.org/index.html

- Regex matches are very useful. I can help locate index of a string
/^a/ =~ 'hayt' #=> nil is nil because hayt doesn't start with a
/^a/ =~ 'ayt' #=> 0 # this is the index

https://ruby-doc.org/core-2.2.0/Regexp.html

Comments