# Lexer sub-group match

**URL:** <https://racket.discourse.group/t/lexer-sub-group-match/2544>\
**Category:** Questions & Answers\
**Tags:** lexer\
**Created:** [November 27, 2023, 5:48pm UTC](https://racket.discourse.group/t/lexer-sub-group-match/2544 "2023-11-27T17:48:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceving](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@ceving](https://racket.discourse.group/u/ceving)\
**Post date:** [November 27, 2023, 5:48pm UTC](https://racket.discourse.group/t/lexer-sub-group-match/2544/1 "2023-11-27T17:48:39Z")

</div>

I have the following code in my lexer in order to parse hex-numbers of the format '#0f'.

```scheme
((:seq #\# (:+ (:or numeric (union-mixed "A" "B" "C" "D" "E" "F"))))
 (token-Hexdecimal (string->number (string-append (substring lexeme 0 1)
                                                  "x"
                                                  (substring lexeme 1)))))

```

The lexer joins the sequence of `#` and the digits into the string `lexeme`. After that I split the string into the `#` and the digits in order to be able to insert the "x" in between. This can't be efficient. Is it anyhow possible to define capturing groups in the regular expression?

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [November 27, 2023, 6:34pm UTC](https://racket.discourse.group/t/lexer-sub-group-match/2544/2 "2023-11-27T18:34:36Z")

</div>

```scheme
(string->number (substring lexeme 1) 16)

```
