Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture groups with regexes using positive lookahead #54

Open
rafaeldelboni opened this issue Dec 7, 2023 · 0 comments
Open

Capture groups with regexes using positive lookahead #54

rafaeldelboni opened this issue Dec 7, 2023 · 0 comments

Comments

@rafaeldelboni
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant