まだ正規表現で消耗してるの?

 まだ正規表現で消耗してるの?

C4c161ae9eeeed8f161197410f7a228a?s=128

Kenichiro Kishida

April 16, 2016
Tweet

Transcript

  1. 1.

    · ͩ ਖ਼ ن ද ݱ Ͱ ফ ໣ ͠

    ͯ Δ ͷ ʁ Մ ಡ ੑ Λ ্ ͛ Δ ͱ ͏ · ͘ ͍ ͘ ͠ ͣ ͻ ͜ 1)1ΧϯϑΝϨϯεࡳຈ ෳࡶͳਖ਼نදݱΛߟ͑Δͷ͸࣌ؒͷແବͩͬͨ ౦ ژ
  2. 5.
  3. 8.

    URI = scheme ":" hier-part [ "?" query ] [

    "#" fragment ] scheme = ALPHA * ( ALPHA / DIGIT / "+" / "-" / "." ) hier-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty https://www.ietf.org/rfc/rfc3986.txt
  4. 11.
  5. 14.

    $rfc3986 = new VerbalExpressions; // scheme $scheme = new VerbalExpressions;

    $scheme->add("http")->maybe("s") ->_or("ftp"); $rfc3986->startOfLine() ->add($scheme) ->add("://"); /^(?:\(\?\:http\)\(\?\:s\)\?\)\|\(\?\:ftp)(?:\:\/\/)/m
  6. 16.
  7. 17.
  8. 18.
  9. 20.
  10. 21.

    pattern = Hexpress.new. start("http"). maybe("s"). with("://"). maybe { words.with(".") }.

    find { matching { [word, "-"] }.multiple }. has("."). either("com", "org"). maybe("/"). ending
  11. 23.

    trait Find { public function find($value = null, $named =

    false) { $param = compact('value', 'named'); return is_callable($value) ? $this->addNested(FindValue::class, $param) : $this->addValue(FindValue::class, $param); } public function capture($value = null) { return $this->find($value); } } class FindValue { use Nested; private $hexpression; private $open; private $close; public function __construct($param) { extract($param); $this->hexpression = is_callable($value) ? new Hexpress($value) : $value; $this->open = $named ? "(?P<{$named}>" : '('; $this->close = ')'; } } class Hexpress def find(value = nil, &block) value ? add_value(Nested::Find, value) : add_nested(Nested::Find, &block) end alias_method :capture, :find module Nested class Find include Nested def initialize(value=nil,&block) @hexpression = value || Hexpress.new.instance_eval(&block) @open, @close = "(", ")" end end end end ࠷ۙͷ1)1ͳΒ͔ͳΓ஧࣮ʹҠ২Մೳ
  12. 24.

    URI = scheme ":" hier-part [ "?" query ] [

    "#" fragment ] scheme = ALPHA * ( ALPHA / DIGIT / "+" / "-" / "." ) hier-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty https://www.ietf.org/rfc/rfc3986.txt
  13. 26.

    private function scheme() { return (new Hexpress()) ->find(function ($hex) {

    $hex->matching(function ($hex) { $hex->letter(); }); $hex->many(function ($hex) { $hex->matching(function ($hex) { $hex->letter()->number()->with('+-.'); }); }, 0); }, 'scheme'); } scheme = ALPHA * ( ALPHA / DIGIT / "+" / "-" / "." ) ̍ ̍    
  14. 28.

    private function scheme() { return (new Hexpress()) ->find(function ($hex) {

    $hex->matching(function ($hex) { $hex->letter(); }); $hex->many(function ($hex) { $hex->matching(function ($hex) { $hex->letter()->number()->with('+-.'); }); }, 0); }, 'scheme'); } scheme = ALPHA * ( ALPHA / DIGIT / "+" / "-" / "." ) pOEϝιουͷୈೋҾ਺ʹ αϒύλʔϯͷ໊લΛࢦఆͰ͖Δ