Deleting all \n which are not followed by a number and a .

36 views
Skip to first unread message

Rainer Krug

unread,
Jul 7, 2023, 12:10:51 PM7/7/23
to BBEdit Talk
I have a file as followed:

4. Leach M et al.: Equity and sustainability in the anthropocene: a
social–ecological systems perspective on their intertwined
futures. Glob Sustain 2018, 1
This important review by some of the leading authorities in the field,
summarizes the state of knowledge concerning the interlinked challenges
of equity and sustainability. Emphasizing that they cannot be addressed
separately, it outlines emerging new thinking which recognizes the multiple perspectives and dimensions involved.
24. Scoones I: The politics of sustainability and development. Annu
Rev Environ Resour 2016:1-27
5.Feola G: Societal transformation in response to global
environmental change: a review of emerging concepts. Ambio
2014, 44:376-390.


Now I want to remove all line breaks (`\n`) except for the ones where the lines starts with a number followed by `.`.

I was thinking: Replace all `xx. ` with `####xx. ` - but how can I do this?

After that, I could remove all `\n` and replace `####` with `\n` and I have it.

Any suggestions?

Thanks,

Rainer

Rainer Krug

unread,
Jul 7, 2023, 12:24:09 PM7/7/23
to BBEdit Talk
OK - found it.
Search Pattern: `^[0-9]\. `
Replace Pattern: `###\0`

Same for two digits.

I was always trying `\1'...

Thanks Pattern Playground!!!

jj

unread,
Jul 7, 2023, 12:43:42 PM7/7/23
to BBEdit Talk
Hi Rainer,

To remove all line breaks (`\n`) except for the ones where the lines starts with a number followed by `.` :

Search Pattern : `\n(?!\d+\.)`
Replace Pattern: ` ` 

Note that the Replace pattern is a space to avoid concatenating together the lines.

Best regards,

Jean

Rainer Krug

unread,
Jul 7, 2023, 12:46:09 PM7/7/23
to BBEdit Talk
OK - thanks. Good to know for the next time - one search instead of 5...
Reply all
Reply to author
Forward
0 new messages