用于提取psycinfo引用的Ruby正则表达式

时间:2011-09-15 20:06:42

标签: ruby regex

我需要一个正则表达式来分离来自大量psycinfo点亮搜索的引用,如下所示:

http://rubular.com/r/bKMoDpAJvY (我无法发布文本 - 有关此编辑控件的内容可怕地发布了)

我只是希望匹配是编号之间的所有文本,但它正在我的脑袋里。还有一个解释很棒,所以我可以学习。

1 个答案:

答案 0 :(得分:2)

teststring.split(/^\d+\./)是否适合您?

使用String#split从字符串中获取一个数组,字符串在正则表达式中分割,在这种情况下是行开头的数字,后跟一个点,可选的一些空格和换行符。

我的测试代码

teststring = DATA.read
teststring.split(/^\d+\.\s*$/).each{|m|
  puts "==========="
  puts m
}

__END__
1. 
Reframing the rocky road: From causal analysis to mindreading as the drama of disposition inference. [References]. 
Ames, Daniel R. 
Psychological Inquiry. Vol.20(1), Jan 2009, pp. 19-23.  
AN: Peer Reviewed Journal: 2009-04633-002. 
Comments on an article by Glenn D. Reeder (see record 2009-04633-001). My misgivings with Reeder's account are relatively minor. For one, I am not sure that the "multiple inference model" label quite captures the essential part of Reeder's argument. Although it suggests the plurality of judgments that perceivers often make, it does not seem to reflect Reeder's central point that, for intentional behaviors, perceivers typically make motive inferences and these guide trait inferences. Another stumbling point for me was the identification of five categories that accounted for "the majority of studies" on dispositional inference (attitude attribution, moral attribution, ability attribution, the silent interview paradigm, and the quiz-role paradigm). These are noteworthy paradigms, to be sure, but they hardly seem to exhaust the research on dispositional inference, which I take as a perceiver's ascription of an enduring trait to a target. (PsycINFO Database Record (c) 2010 APA, all rights reserved)
Publication Date
Jan 2009
Year of Publication
2009
E-Mail Address
Ames, Daniel R.: da358@columbia.edu
Other Publishers
Lawrence Erlbaum; US


Link to the Ovid Full Text or citation:
http://ovidsp.ovid.com/ovidweb.cgi?T=JS&CSC=Y&NEWS=N&PAGE=fulltext&D=psyc6&AN=2009-04633-002

Link to the External Link Resolver:
http://diglib1.bham.ac.uk:3210/sfxlcl3?sid=OVID:psycdb&id=pmid:&id=doi:10.1080%2F10478400902744253&issn=1047-840X&isbn=&volume=20&issue=1&spage=19&pages=19-23&date=2009&title=Psychological+Inquiry&atitle=Reframing+the+rocky+road%3A+From+causal+analysis+to+mindreading+as+the+drama+of+disposition+inference.&aulast=Ames&pid=%3Cauthor%3EAmes%2C+Daniel+R%3C%2Fauthor%3E%3CAN%3E2009-04633-002%3C%2FAN%3E%3CDT%3EComment%2FReply%3C%2FDT%3E 




2. 
Everyday Solutions to the Problem of Other Minds: Which Tools Are Used When? [References]. 
Ames, Daniel R. 
Malle, Bertram F [Ed];  Hodges, Sara D [Ed]. (2005). Other minds: How humans bridge the divide between self and others.  (pp. 158-173). xiii, 354 pp. New York, NY, US: Guilford Press;  US.  
AN: Book: 2005-09375-010. 
(from the chapter) Intuiting what the people around us think, want, and feel is essential to much of social life. Some scholars have gone so far as to declare the "problem of other minds"--whether a person can know if anyone else has thoughts and, if so, what they are--intractable. And yet countless times a day, we solve such problems with ease, if not perfectly then at least to our own satisfaction. What strategies underlie these everyday solutions? And how are these tools employed? This chapter offers 4 contingencies about when various inferential tools might be used. First, that affect qualifies behavior in the near term: perceived remorseful affect can lead to ascriptions of good intent to harm-doers in the short run, but repeated harm drives long-run ascriptions of bad intent. Second, that perceived similarity governs projection and stereotyping: perceptions of general similarity to a target typically draw a mindreader toward projection and away from stereotyping; perceived dissimilarity does the opposite. Third, that cumulative behavioral evidence supersedes extratarget strategies: projection and stereotyping will drive mindreading when behavioral evidence is ambiguous, but as apparent evidence accumulates, inductive judgments will dominate. Fourth, that negative social intention information weighs heavily in mindreading: within a mindreading strategy, cues signaling negative social intentions may dominate neutral or positive cues; between mindreading strategies, those strategies that signal negative social intentions may dominate. These contingencies have varying degrees of empirical support and would benefit from additional research and thinking. (PsycINFO Database Record (c) 2010 APA, all rights reserved)
Publication Date
2005
Year of Publication
2005


Link to the Ovid Full Text or citation:
http://ovidsp.ovid.com/ovidweb.cgi?T=JS&CSC=Y&NEWS=N&PAGE=fulltext&D=psyc5&AN=2005-09375-010

Link to the External Link Resolver:
http://diglib1.bham.ac.uk:3210/sfxlcl3?sid=OVID:psycdb&id=pmid:&id=doi:&issn=&isbn=1-59385-187-1&volume=&issue=&spage=158&pages=158-173&date=2005&title=Other+minds%3A+How+humans+bridge+the+divide+between+self+and+others.&atitle=Everyday+Solutions+to+the+Problem+of+Other+Minds%3A+Which+Tools+Are+Used+When%3F&aulast=Ames&pid=%3Cauthor%3EAmes%2C+Daniel+R%3C%2Fauthor%3E%3CAN%3E2005-09375-010%3C%2FAN%3E%3CDT%3EChapter%3C%2FDT%3E 

导致:     ===========

===========

Reframing the rocky road: From causal analysis to mindreading as the drama of disposition inference. [References]. 
Ames, Daniel R. 
Psychological Inquiry. Vol.20(1), Jan 2009, pp. 19-23.  
AN: Peer Reviewed Journal: 2009-04633-002. 
Comments on an article by Glenn D. Reeder (see record 2009-04633-001). My misgivings with Reeder's account are relatively minor. For one, I am not sure that the "multiple inference model" label quite captures the essential part of Reeder's argument. Although it suggests the plurality of judgments that perceivers often make, it does not seem to reflect Reeder's central point that, for intentional behaviors, perceivers typically make motive inferences and these guide trait inferences. Another stumbling point for me was the identification of five categories that accounted for "the majority of studies" on dispositional inference (attitude attribution, moral attribution, ability attribution, the silent interview paradigm, and the quiz-role paradigm). These are noteworthy paradigms, to be sure, but they hardly seem to exhaust the research on dispositional inference, which I take as a perceiver's ascription of an enduring trait to a target. (PsycINFO Database Record (c) 2010 APA, all rights reserved)
Publication Date
Jan 2009
Year of Publication
2009
E-Mail Address
Ames, Daniel R.: da358@columbia.edu
Other Publishers
Lawrence Erlbaum; US


Link to the Ovid Full Text or citation:
http://ovidsp.ovid.com/ovidweb.cgi?T=JS&CSC=Y&NEWS=N&PAGE=fulltext&D=psyc6&AN=2009-04633-002

Link to the External Link Resolver:
http://diglib1.bham.ac.uk:3210/sfxlcl3?sid=OVID:psycdb&id=pmid:&id=doi:10.1080%2F10478400902744253&issn=1047-840X&isbn=&volume=20&issue=1&spage=19&pages=19-23&date=2009&title=Psychological+Inquiry&atitle=Reframing+the+rocky+road%3A+From+causal+analysis+to+mindreading+as+the+drama+of+disposition+inference.&aulast=Ames&pid=%3Cauthor%3EAmes%2C+Daniel+R%3C%2Fauthor%3E%3CAN%3E2009-04633-002%3C%2FAN%3E%3CDT%3EComment%2FReply%3C%2FDT%3E 




===========

Everyday Solutions to the Problem of Other Minds: Which Tools Are Used When? [References]. 
Ames, Daniel R. 
Malle, Bertram F [Ed];  Hodges, Sara D [Ed]. (2005). Other minds: How humans bridge the divide between self and others.  (pp. 158-173). xiii, 354 pp. New York, NY, US: Guilford Press;  US.  
AN: Book: 2005-09375-010. 
(from the chapter) Intuiting what the people around us think, want, and feel is essential to much of social life. Some scholars have gone so far as to declare the "problem of other minds"--whether a person can know if anyone else has thoughts and, if so, what they are--intractable. And yet countless times a day, we solve such problems with ease, if not perfectly then at least to our own satisfaction. What strategies underlie these everyday solutions? And how are these tools employed? This chapter offers 4 contingencies about when various inferential tools might be used. First, that affect qualifies behavior in the near term: perceived remorseful affect can lead to ascriptions of good intent to harm-doers in the short run, but repeated harm drives long-run ascriptions of bad intent. Second, that perceived similarity governs projection and stereotyping: perceptions of general similarity to a target typically draw a mindreader toward projection and away from stereotyping; perceived dissimilarity does the opposite. Third, that cumulative behavioral evidence supersedes extratarget strategies: projection and stereotyping will drive mindreading when behavioral evidence is ambiguous, but as apparent evidence accumulates, inductive judgments will dominate. Fourth, that negative social intention information weighs heavily in mindreading: within a mindreading strategy, cues signaling negative social intentions may dominate neutral or positive cues; between mindreading strategies, those strategies that signal negative social intentions may dominate. These contingencies have varying degrees of empirical support and would benefit from additional research and thinking. (PsycINFO Database Record (c) 2010 APA, all rights reserved)
Publication Date
2005
Year of Publication
2005


Link to the Ovid Full Text or citation:
http://ovidsp.ovid.com/ovidweb.cgi?T=JS&CSC=Y&NEWS=N&PAGE=fulltext&D=psyc5&AN=2005-09375-010

Link to the External Link Resolver:
http://diglib1.bham.ac.uk:3210/sfxlcl3?sid=OVID:psycdb&id=pmid:&id=doi:&issn=&isbn=1-59385-187-1&volume=&issue=&spage=158&pages=158-173&date=2005&title=Other+minds%3A+How+humans+bridge+the+divide+between+self+and+others.&atitle=Everyday+Solutions+to+the+Problem+of+Other+Minds%3A+Which+Tools+Are+Used+When%3F&aulast=Ames&pid=%3Cauthor%3EAmes%2C+Daniel+R%3C%2Fauthor%3E%3CAN%3E2005-09375-010%3C%2FAN%3E%3CDT%3EChapter%3C%2FDT%3E 

第一个空“”已过时,您可以将其删除。


我找到了另一种使用String#scan的解决方案:

(teststring + "99.\n").scan(/^\d+\.\s*\n(.*?)(?=^\d+\.\s*\n)/m).each{|m|
  puts "==========="
  puts m
}

说明:

  • ^\d+\.\s*\n在第一行的第一行查找带点的数字。忽略尾随空格
  • (.*?)采取一切,但不贪婪(使用最短命中)
  • (?=^\d+\.\s*\n)检查下一个条目,但不要使用它
  • m使用多行代码
  • (teststring + "99.\n")此解决方案将丢失最后一个条目。所以我们添加一个'endtag'