Q:

What is wrong with my regular expression in R?

I am trying to extract the label, name, address, city, zip, and distance from the following text:
A

Carl's Jr.

308 WESTWOOD PLAZA

LOS ANGELES, CA 90095-8355

0.0 mi.

B

Carl's Jr.

2727 SANTA MONICA

SANTA MONICA, CA 90404-2407

4.8 mi.

...
...

Here is my regular expression pattern and code, but I get a matrix of NA values.
p <- "(^[AZ]\\n)^(\\w+.\\w+\\s\\w+.\\s*\\w*)\\n^(\\d+\\w+\\s*\\w*\\s*\\w*)\\n^(\\w+\\s*\\w*),\\s(CA)\\s(\\d+-*\\d*)\\n^(\\d+.\\d*)\\smi."

matches <- str_match(cj, p)

Do I have a syntax error in my pattern?

A:

Maybe try strsplit() instead.  See regex101 for an explanation of the regex used below.  Afterwards, we can figure out how many rows there will be by finding the number of single character elements.
s <- strsplit(x, "\n+|, | (?=[0-9]+)", perl = TRUE)[[1]]
as.data.frame(matrix(s, sum(nchar(s) == 1), byrow = TRUE))
#   V1         V2                 V3           V4 V5         V6      V7
# 1  A Carl's Jr. 308 WESTWOOD PLAZA  LOS ANGELES CA 90095-8355 0.0 mi.
# 2  B Carl's Jr.  2727 SANTA MONICA SANTA MONICA CA 90404-2407 4.8 mi.

Data:
x <- "A\n\nCarl's Jr.\n\n308 WESTWOOD PLAZA\n\nLOS ANGELES, CA 90095-8355\n\n0.0 mi.\n\nB\n\nCarl's Jr.\n\n2727 SANTA MONICA\n\nSANTA MONICA, CA 90404-2407\n\n4.8 mi."

