PHP中的代码
<?php
$str = "CSIR-National Botanical Research Institute, Plant Transgenic Laboratory, U.P., India. Electronic address: i.sanyal@nbri.res.in.";
preg_match("/([A-Z][^\s,.]+[.]?\s[(]?)*(Hospital|University|Institute|Law School|School of|Academy|College)[^,\d]*(?=,|\d)/", $str, $org_arr);
echo $org_arr[0];
?>
输出
CSIR-国家植物研究所
此正则表达式从给定的 PHP 字符串中提取医院、大学、研究所、学校、学院或学院。我尝试在 python 中执行相同的正则表达式,但它不起作用。
Python 中的代码
import re
line = "CSIR-National Botanical Research Institute, Plant Transgenic Laboratory, U.P., India. Electronic address: i.sanyal@nbri.res.in."
match = re.search(r'/([A-Z][^\s,.]+[.]?\s[(]?)*(Hospital|University|Institute|Law School|School of|Academy|College)[^,\d]*(?=,|\d)/', line)
print(match.group(0))
给出错误信息
回溯(最近一次调用最后一次):文件“C:\Users\Ghost Rider\Documents\Python\temp.py”,第 4 行,在 print(match.group(0)) AttributeError: 'NoneType' object has no attribute '团体'
精慕HU
相关分类