Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

Cybozu

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.     l "Cybozu" == "Cybozu"  l

    "Cybozu" in "Cybozu, Inc."
  3.     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 ")
  4.   ls /usr/bin/vi* l * G l ? G

    l [abc] G  : ) )( 1 .1 1 //
  5.     | "   (...) $&

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

     + 1   * 0   {min, max} minmax    bc*: "b", "bcccc"   l   >   (ab)+: "ab", "abababab"    (ab|cd){1,3}: "ababcd", "cdab", "cd"  
  7.     .  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" 
  8.  ^    $    

    ^default_type +[a-zA-Z/-]+;$ "default_type application/octet-stream;"   
  9. ( 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 ,
  10.  HTTP"$'- " (=GET) "URI(=/index.html) HTTP !#(=1.1),+ #* /: "GET

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

    N m = pat.match('Kintone') l : l /. l
  12.  ¥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 /
  13. pat = re.compile(r'~~~') r '~~~' raw string  l ¥

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

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

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

    grep -E 'le?s' l | %  )"!+%  )"(+ $& l -E '#*    grep re regular expression re
  17.        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
  18.    7 8 . 5 I l 55

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

    ) l P P M h n M n n M {1,64} : r
  20. (¥w|[_-]){1,64}@   "__"    ( ) ,

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

    _ 2 l (¥w|-){1,64}@  1 R l l 51_ E
  22.   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]'
  23.   : l / . .  l /

    . . .  l / . . .
  24.  /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)   *+,- %&"'
  25.   /usr/share/dict/words 3/#/,& -$  */#(/ # 0 

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

     os l : 20182030 l : 020 # l ty-2018-15 l os-2019-0
  27.   ! &,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/"   ()  ? /#+"