0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

正規表現 python vs shellscript

Posted at

置換表現

問題1

内容1
以下のメールアドレスを一括で置換したい
'aaa@xxx.com bbb@yyy.com ccc@zzz.com'
                 ↓
 ABC@xxx.com ABC@yyy.com ABC@zzz.com
python.py
s = 'aaa@xxx.com bbb@yyy.com ccc@zzz.com'

print(re.sub('[a-z]*@', 'ABC@', s))
shell.sh
#  mail.text に'aaa@xxx.com bbb@yyy.com ccc@zzz.com'を記入して

# その1
sed -e  "s/*@/ABC@/g" mail.txt  

# その2
sed -e  "s/[a-z]*@/ABC@/g" mail.txt  

問題2

内容2
以下の「文章」を単語区切りにしたい.
'Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.'
python.py
str = 'Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.'

# ,と.を除去
str = re.sub('[,\.]', '', str)  
shell.sh
# memo.textに「文章」を記入して

sed -e  "s/\.//g"  -e  "s/\,//g" memo.txt  
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?