3

I have some text containing . A....
The regex is [.][\s][\s][!A-Z] This finds the containing string. The problem is, that I don't know how to replace all of it with \n except the [A-Z]

ctwheels
  • 21,901
  • 9
  • 42
  • 77
user3776738
  • 214
  • 2
  • 10
  • 27
  • Just as a side-note `[]` is not necessary around `\s`. Also, `[.]` can be rewritten as `\.`. So `\.\s\s[!A-Z]` is the same as your original regex (but shorter). Also, instead of declaring `\s\s`, use `\s{2}`. It uses 1 less step (at the expense of 1 extra character). Also, you can use grundic's solution or `\.\s{2}(?=[!A-Z])` and simply replace with `\n`. This option doesn't store a grouping into memory, but rather the position (it should perform slightly faster) – ctwheels Nov 01 '17 at 13:09

1 Answers1

6

You can use grouping and back refer to them by \1, \2, etc.

Change your regex to [.][\s][\s]([!A-Z]) and replace it with \n\1

grundic
  • 4,641
  • 3
  • 31
  • 47