Skip to content

Capture groups with regexes using positive lookahead  #54

@rafaeldelboni

Description

@rafaeldelboni

How can I get all the captured groups with the following positive lookahead regex?

My attempts:

(ppcre:all-matches-as-strings "(?=one|two|three|four|five|six|seven|eight|nine|ten)" "eighthree") ; => ("" "")
(ppcre:all-matches-as-strings "(?=(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))" "eighthree") ; => ("" "")
(ppcre:scan-to-strings "(?=(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))" "eighthree") ; => "" #(NIL NIL NIL NIL NIL NIL NIL "eight" NIL)
(ppcre:scan-to-strings "(?=(one|two|three|four|five|six|seven|eight|nine|ten))" "eighthree") ; => "" #("eight")
(cl-ppcre:register-groups-bind
      (one two three four five six seven eight nine)
      ("(?=(one)|(two)|(three)|(four)|(five)|(six)|(seven)|(eight)|(nine))" "eighthree" :sharedp t)
    (remove nil (list one two three four five six seven eight nine))) ; => ("eight")

You can get both groups using regex101 for example:
https://regex101.com/r/mJmQwA/1
https://regex101.com/r/XTw3x7/1

image

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