3 ms·
Here is one possible translation of asperous’s simplified email regex into a Parslet parser: #!/usr/bin/env ruby original_regex = /^ ( [a-z0-9]+ @ [a-z]
by roryokane 13y ago
Here is one possible translation of asperous’s simplified email regex into a Parslet parser:
#!/usr/bin/env ruby
original_regex = /^ ( [a-z0-9]+ @ [a-z]+ \. [a-z]+ ) $/ix
require 'parslet'
include Parslet
local_part = match['A-Za-z0-9'].repeat(1)
letters = match['A-Za-z'].repeat(1)
domain_part = letters >> str('.') >> letters
email_parser = local_part >> str('@') >> domain_part
user_input = "foo#bar.com"
matches_regex = original_regex.match(user_input)
matches_parser = email_parser.parse(user_input)
asperous’s regex: https://news.ycombinator.com/item?id=6319435 https://news.ycombinator.com/item?id=6319435
Parslet info: http://kschiess.github.io/parslet/ http://kschiess.github.io/parslet/
- deleted 13y ago[deleted]