Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Simple pattern causing infinite recursion? #96

@MichaelChirico

Description

@MichaelChirico

I'm trying to replace text a specific column of the line, hence the natural approach I saw is:

gsub("^(.{N})FOO", "\\1BAR", x)

i.e., capture whatever the first N characters are and, if they are followed by FOO, replace FOO with BAR (retaining whatever the first N characters were).

Here's my attempt in rex():

N = 12L
pattern <- rex(
  start,
  capture(n_times(anything, N)),
  "function"
)

But the resulting pattern generates infinite recursion (it seems):

grepl(ptn, "  lapply(y, function(yi) {", perl = TRUE)
# Warning message:
# In grepl(ptn, "  lapply(y, function(yi) {", perl = TRUE) :
#   back-tracking limit reached in PCRE for element 1

Actually, I am suspecting this might be an R / PCRE regex bug given how hard it was to come up with a more minimal reprex...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions