bogdan@example.com
\w+@\w+(\.\w+)+
/\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
etc.
+380(67)222-33-00
bogdan@example.com
192.168.0.1
ab
aab
abb
abbb
aabb
aaab
S -> aS
S -> aR
R -> bR
R -> b
S -> [0-z]N
N -> [0-z]N
N -> @D
D -> [0-z]D
D -> [0-z].Z
Z -> [0-z]Z
Z -> [0-z]
S -> aSb
S -> ab
ab
aabb
aaabbb
aaaabbbb
def match_aabb_pattern?(string)
string.each_char.with_index.each do |c, i|
case c
when 'a'
count_a += 1
when 'b'
return count_a == string.size - i - 1
else
return false
end
end
return false
end
"12*(2+8/(13.5+7))" =>
[
'12', '*', '(', '2', '+', '8' '/',
'(', '13.5', '+', '7', ')', ')'
]
['12', '*', ['(', '2', '+', '8' '/', '(', '13.5', '+', '7', ')', ')'] ] [left = '12', operator, right = [...]] ['12', '*', [ '2', '+', '8' '/', '(', '13.5', '+', '7', ')'] ] Cleanup useless brackets ( ) ['12', '*', [ '2', '+', [ '8' '/', '(', '13.5', '+', '7', ')' ] ] ] # Repeat for right and left node ['12', '*', [ '2', '+', [ '8', '/', [ '13.5', '+', '7', ] ]]] # Repeat for right and left node
def evaluate(ast)
if ast.is_a?(Array)
left, operator, right = ast
evaluate(left).send(operator, evaluate(right))
else
ast.to_f
end
end
/users/:id(.:format)
(/locale/:locale)/users/:id(.:format)
(/locale/:locale(/currency/:currency))/users/:id(.:format)
/users/:id(.:format)
Token | Type |
---|---|
/ | SLASH |
users | LITERAL |
/ | SLASH |
:id | SYMBOL |
( | LPAREN |
. | DOT |
:format | SYMBOL |
) | RPAREN |
group : LPAREN expressions RPAREN { ... } ;expressions : expressions expression { ... } | expression { ... } | or ;# Simplied! expression : symbol | literal | slash | dot | group | star ;
racc -l -o parser.rb parser.y
Software developers have unique opportunity to support economics of our country. We are the only one that can really bring money to Ukraine.