Question: I'm having troubles with re.sub. I understand from other answers that this is due to the fact I'm referencing to a capturing group that I don't have.

My question is: how do I adjust my code to have a valid group?

```
s = "hello a world today b is sunny c day"
markers = "a b c".split()
pattern = r'\b' + ' (?:\w+ )?(?:\w+ )?'.join(markers) + r'\b'
text = re.sub(pattern, r'<b>\1</b>', s)   # this gives error

```

I want to have this : `"hello <b>a world today b is sunny c</b> day"`

Answer: 
You don't have any groups in your regex.

`(?:...)` is a non capture group, I guess you want

```
pattern = r'\b(' + ' (?:\w+ )?(?:\w+ )?'.join(markers) + r')\b'

```
This code can get the result what you want.I have tested.

```
import re
s = "hello a world today b is sunny c day"
pat = r'(a.*c)'
result = re.sub(pat,r'<b>\1</b>',s)

```