简体   繁体   中英

How to extract certain string from a line of string using find.()

file_name_to_preprocessing_method("heloc_dataset_v1(exc empty rows.).csv_pre(-1,asis).csv")

should return the string "(-1,asis)", possibly using .find() .

在此处输入图像描述

Using re.findall for a regex approach:

inp = "file_name_to_preprocessing_method(\"heloc_dataset_v1(exc empty rows.).csv_pre(-1,asis).csv\")"
matches = re.findall(r'\bcsv_pre(\(.*?\))', inp)
print(matches[0])  # (-1,asis)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM