On Feb 11, 2007, at 7:38 PM, jeff newman wrote:
Hello everyone,
I'm new to many things here -- textmate, regular expressions, etc, etc. so I hope this isn't too far off topic for this list (apologies in advance if it is). I'm trying to figure out how to do something using find/replace. I have a long bibliography that was sent to me as a single line of text. I'm trying to find a quick and elegant way to insert line breaks between each of the individual citations.
Here is an example of the text I'm working with:
Baddeley, A. "Working Memory." Science. 255: 556-559,1992. Baecker, R. J. Grudin, W. Buxton, et al. Readings in Human- Computer Interaction: Toward the Year 2000. USA: Morgan Kaufinann Publishers, Inc. 1995. Bevirt, B. "Designing Hypertext Navigation Tools.'' Digital Information Group, National Center for Atmospheric Research web site: < http://www. schlucar/dig/bra.inb/ design/navtool.D.html>. 1996. Chandler, P. and J. Sweller. ''Cognitive Load Theory and the Format of Instruction." Cognition and Instruction. 8: 293-332, 1991. Chandler, P. and J. Sweller. 'The Split Attention Effect as a Factor in the Design of Instruction." British Journal of Education Psychology. 62: 233-246, 1992.
I'm just figuring out how to use regular expressions (sorry, not a programmer) and I've been able to successfully select the endpoint of each of the citations using:
\d{4}.\s
My problem comes about when I try to replace the space represented by \s with a carriage return. I'm not sure how to structure this in the find/replace dialogue. Is anyone willing to point me in the right direction here? I'm hoping to end up with something that looks like:
Two ways:
First way (using a group to match the text we want to keep, and use $1 to refer to it in the substitution string): Search for: (\d{4}.)\s Replace by: $1\n
Second way (using a lookbehind for the \d{4}. stuff): Search for: (?<=\d{4}.)\s Replace by: \n
Btw, you would probably want \s+ in those instead of just \s, to absorb more than one spaces, if that happens. Keep in mind, this method of yours will also break at the "Year 2000." line below. Not easy to avoid that though, hopefully it's only a few cases.
Baddeley, A. "Working Memory." Science. 255: 556-559,1992. Baecker, R. J. Grudin, W. Buxton, et al. Readings in Human- Computer Interaction: Toward the Year 2000. USA: Morgan Kaufinann Publishers, Inc. 1995.
Bevirt, B. "Designing Hypertext Navigation Tools.'' Digital Information Group, National Center for Atmospheric Research web site: < http://www. schlucar/dig/bra.inb/design/navtool.D.html>. 1996.
Chandler, P. and J. Sweller. ''Cognitive Load Theory and the Format of Instruction." Cognition and Instruction. 8: 293-332, 1991. Chandler, P. and J. Sweller. 'The Split Attention Effect as a Factor in the Design of Instruction." British Journal of Education Psychology. 62: 233-246, 1992.
I'm assuming you meant to break after the 1991 here? ^^
Thank you for any help you can offer.
-- j.
Haris