$30 off During Our Annual Pro Sale. View Details »

2018-09-正規表現 / 2018-09 regular expression

2018-09-正規表現 / 2018-09 regular expression

Cybozu
PRO

July 10, 2018
Tweet

More Decks by Cybozu

Other Decks in Programming

Transcript

  1.    / 4 = 088 4 92 3

    4 9 42 1 # 04: / 4 .
  2.         

  3.     l "Cybozu" == "Cybozu"  l

    "Cybozu" in "Cybozu, Inc."
  4.     s = 'If the condition is

    true, then do the indented statements.' if s != 'This is a pen': print('s is not "This is a pen") if 'cond' in s: print('s contains "cond"') if s.startswith('If '): print('s starts with "If ")
  5.   ls /usr/bin/vi* l * G l ? G

    l [abc] G  : ) )( 1 .1 1 //
  6.  :  [a-zA-Z0-9_-]{1,64}@[a-zA-Z0-9_-]{1,64}[a-zA-Z0-9_-¥.]{1,64} l l Abc@gmail.com l takahiro-tsuruda@cybozu.co.jp

  7.   l %$ ,/'# ! + l *)" -.

    (&
  8.   : " / . /

  9.       Ab l "

  10.     | "   (...) $&

    (' () % )  * l a|b|c : "a", "b", "c"  l a(bc|ef) : "abc", "aef"  l! +# > $&
  11.        ? 01 

     + 1   * 0   {min, max} minmax    bc*: "b", "bcccc"   l   >   (ab)+: "ab", "abababab"    (ab|cd){1,3}: "ababcd", "cdab", "cd"  
  12.  "HTTP/1.1", "HTTP/2.0"    "."   "¥."

  13.     .  1  […] 

      1  [^…]    1  [a-z] [abcdefghijklmnopqrfzuvwzyz]  l a.c : "abc", "a1c"  l [abc] : "a", "b", "c"  l [^abc] : "d", "1", "@"  l [abc]+ : "a", "aabcaac", "b" 
  14.  ^    $    

    ^default_type +[a-zA-Z/-]+;$ "default_type application/octet-stream;"   
  15.  ¥1, ¥2 :1,2 ()   <(div|p)>.*<¥/¥1> l "<div>aaa</div>"

    l "<p> </p>"   
  16. ( 3: "Author:Taro""User:Jiro" 0&4 TaroJiro./ '(  (User|Author):(¥w+) ! $*

     ¥1 "User"  "Author" ,¥2 "Taro" ,  ¥1-2…  (?:User|Author): (¥w+) * %)#"1+  ¥1  Taro  Jiro ,
  17.   [a-zA-Z0-9_-]{1,64}@[a-zA-Z0-9_-]{1,64}[a-zA-Z0-9_-¥.]{1,64} l [a-zA-Z0-9_-] :   "_" 

    "-"  l {1,64} :  164
  18.  HTTP"$'- " (=GET) "URI(=/index.html) HTTP !#(=1.1),+ #* /: "GET

    /index.html HTTP/1.1"  "GET", "/index.html", "1.1" ,+  https://regexr.com (  Tools  Details  ,+ &%). 
  19.  33 / 3 /. 3 pat = re.compile(r'[kK]intone') l

    N m = pat.match('Kintone') l : l /. l
  20.  ¥w [a-zA-Z0-9_] l  ¥W [^a-zA-Z0-9_]  ¥s [

    ¥t¥n¥r¥f¥v] l  ¥S [^ ¥t¥n¥r¥f¥v] : 3# 3 / - .- - 33 / 3 /
  21. pat = re.compile(r'~~~') r '~~~' raw string  l ¥

    $  !   $ # "% & $ ': ¥n 
  22. r… ¥Python2-% $&0+1,#2-(   ¥ 2-4*.   ¥¥

    /  raw string % $& ¥2-" !'/  ¥¥¥¥/)3
  23. E cE e E  I gM _ / #

    / 3 . / / / 3  g I Mad / # / 3 . / .  T / # / 3 . /  b M / # / 3 . : / : 3
  24.       $ ls /bin |

    grep -E 'le?s' l | %  )"!+%  )"(+ $& l -E '#*    grep re regular expression re
  25.        9/. cl r

    c l pb r oa gi h sed "/^user/ s/[tT]suruda/suzuki/" l user c tsuruda suzuki m sed -e "s/^#?¥s*PermitEmptyPasswords.*/PermitEmptyPasswords yes/" /etc/ssh/sshd_config l /etc/ssh/sshd_config PermitEmptyPasswords c PermitEmptyPasswords yes  d n 9/. e 1:: 9 56: 1 25/. 1 :/5 360 64 /5:8
  26.    7 8 . 5 I l 55

    / 7 8 . 5 7 C import re re.compile(r'(¥w|[_-]){1,64}@').match("_" * 25) :
  27.   o t M y V P PMe (

    ) l P P M h n M n n M {1,64} : r
  28.   a(b|c) )      

        (
  29.      (¥w|[_-]){1,64}@

  30.      (¥w|[_-]){1,64}@ ¥w : [a-zA-Z0-9_] 

  31.      (¥w|[_-]){1,64}@ ¥w : [a-zA-Z0-9_] 

    (¥w|[_-]) "
  32. (¥w|[_-]){1,64}@   "__"    ( ) ,

    -  ( ( ) , - ( ( ) , - @ 1 ( ) , -  @ ( ) , -  ( ) , - @ 1 ( ) , - ( ) , - ( ( ) , - @ 1 ( ) , - @ ( ) , - ( ) , - @ 1 ( ) , - 46 4 2 6
  33. (¥w|[_-]){1,64}@ "  2  2 l " 2 

    _ 2 l (¥w|-){1,64}@  1 R l l 51_ E
  34.  (".%/& .% - #0 1 $  ) '

    ,* !+
  35.   jq : *0&-0JSON'!72$. JSON25/8:(.341 ?@ ) %<C+#%,#" =>

    96  <C;6A B $ curl –s 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '[.[].commit.message]'
  36.   : l / . .  l /

    . . .  l / . . .
  37.     l J

  38.  /etc/network/interfaces IP ,-(# )  import re ip_addr_pat =

    re.compile(r'!+$') with open(…) as f: for line in f: m = ip_addr_pat.search(line) if m is None: continue print(…)  m.group(0)   *+,- %&"'
  39.   /usr/share/dict/words 3/#/,& -$  */#(/ # 0 

    2 $ grep -iE "%. '" /usr/share/dict/words aba aga aha ...   l !1") l +/# ^ $
  40.  ""-- "  !$   l ": ty

     os l : 20182030 l : 020 # l ty-2018-15 l os-2019-0
  41.   ! &,1- (3$4 $4*' ) 080-1234-5678 // -

     090(9876)5432 // ( ) . 08015247682 // .   0 $ echo "080-1234-5678 090(9876)5432 08015247682" | sed -E "s/%. )/¥1 ¥2 ¥3/"   ()  ? /#+"