我正在尝试从这个 webpage 中提取可解析的引用信息使用 python 。例如,对于列出的页面,我将提取 pl/111/148 和 pl/111/152。下面列出了我当前的正则表达式,但它似乎在可解析引用之后返回了所有内容。这可能很简单,但我对正则表达式比较陌生。提前致谢。
re.findall(r'^parsable-cite=.*>$',page)
最佳答案
我强烈推荐使用这个正则表达式,它将捕获你想要的内容:
re.findall(r'parsable-cite=\\\"(.*?)\\\"\>',page)
解释:
parsable-cite= matches the characters parsable-cite= literally (case sensitive)
\\ matches the character \ literally
\" matches the character " literally
1st Capturing group (.*?)
.*? matches any character (except newline)
Quantifier: Between zero and unlimited times, as few times as possible,
expanding as needed
\\ matches the character \ literally
\" matches the character " literally
\> matches the character > literally
使用 ? 是关键;)
希望这对您有所帮助。
关于python - 在python中使用正则表达式匹配字符串的开头和结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22699040/