0
3

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.

正規表現でURLの余分な文字列を除去

Posted at
import re

pattern = re.compile(r"(^[^-]*-[^-]*)-[^-,]*")

with open('out.csv', encoding='utf-8') as f:
    for row in f.readlines():
        m = pattern.match(row)
        if m:
            print(m.group(1))

out.csv

https://www.abcde.com/-0w69e7e1w00-あいうえお
https://www.abcde.com/-0w69e7e9w70-かきくけこ
https://www.abcde.com/-0w08e1e0w00-さしすせそ
https://www.abcde.com/-0w69e7e1w70-たちつてと
https://www.abcde.com/-0w69e6e2w54-なにぬねの
0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?