鱼C论坛

 找回密码
 立即注册
查看: 2361|回复: 9

关于提取word文档中特定字符的问题。

[复制链接]
发表于 2019-11-14 03:50:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
还是从word文档中提取一些字符,但是这些字符都是些,英语论文的引用格式,而且不能用re模块。

比如这两段是我通过python-docx读取下来的两端内容。

str1='were blamed for adolescent violence and suicide (Martin et al., 1993; Weinstein, 2000) 1. The shocking nature of these crimes are memorable, and as such are easily brought to mind when people think of heavy metal music. By discussing the availability heuristic—basing the likelihood of an event on the ease with which it comes to mind—educators can challenge students to consider what evidence they have used to assess the impact of music on behavior (Kahneman et al., 1982).'

str2='people from the supposedly harmful effects of listening to heavy metal music. The PMRC can be used as a way to introduce further logical fallacies, such as the emotional fallacy (e.g., Slovic and Peters, 2006) and the argument from authority (Smith, 2010). '

如何取到(Martin et al., 1993; Weinstein, 2000),(Kahneman et al., 1982)(e.g., Slovic and Peters, 2006)(Smith, 2010),这些字符串呢。。

麻烦大佬们帮我想想办法,我头都炸了。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-11-14 03:54:10 | 显示全部楼层
哦对了,还包括不能使用string,就只能通过普通循环来写。我反正是没想出来。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-14 05:20:57 | 显示全部楼层
还有,

str3='Contrary to the concerns of the PMRC, people who were fans of heavy metal music in adolescence fared better in many aspects of their adult lives than people who were not fans. Howe et al. (2015) surveyed people who were adolescent fans of the heavy metal in the 1980's. In comparison to college students and to a middle-aged comparison group, heavy metal fans reported that they were happier during adolescence, and were better adjusted as adults7. While the Howe et al. (2015) study shows that listening to heavy metal does not appear to have any negative long-term effects, what about the impact of listening to aggressive music on people who are fans of heavy metal?'

如何从这里面取到Howe et al. (2015),这几个字符呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 06:58:23 From FishC Mobile | 显示全部楼层
qq819343713 发表于 2019-11-14 05:20
还有,

str3='Contrary to the concerns of the PMRC, people who were fans of heavy metal music in a ...

你就干脆连str相关也不能用,多好
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 09:23:34 | 显示全部楼层
wp231957 发表于 2019-11-14 06:58
你就干脆连str相关也不能用,多好

哈哈,老哥炸了。不过也是,编程本来就不用把自己限制的太死,其实我也不知道为什么会有人问这样的问题,还各种限制,不让用这不让用那
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 09:41:53 | 显示全部楼层
本帖最后由 Jery_wang09 于 2019-11-14 09:43 编辑

直接通过()来匹配,把其他字符剥离掉就好了
不能用string,那就直接手写一个字符串去匹配即可,再套用循环,虽然办法笨,但是能解决这个问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 10:04:53 | 显示全部楼层
本帖最后由 Jery_wang09 于 2019-11-14 10:06 编辑
qq819343713 发表于 2019-11-14 05:20
还有,

str3='Contrary to the concerns of the PMRC, people who were fans of heavy metal music in a ...


这个难度有点大
实在不行把“Howe et al.”这个字符串写死去硬匹配吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 10:08:38 | 显示全部楼层
为啥我的回复没了。。。。
实在不行把“Howe et al.”写死硬匹配吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 11:19:39 | 显示全部楼层
正则表达式都不让用?
那就循环呗,先匹配左括号的位置,再匹配成对的右括号的位置,然后把中间的放到一个字符串中呗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-20 18:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表