0

I am trying to compile the following regex:

regex = re.compile(r'(?P<ls_pci>[\w\d:]+)[\s-\w\d]+\[(?P<device_name>[\w\s:\d-]+)')

On regex101.com it works, but not compiling on my server.

What am I missing?

Thanks

urban
  • 5,392
  • 3
  • 19
  • 45
  • 1
    What a mess of a regex you have. How can it work anywhere? Please provide a link to the fiddle where it works. It looks as if you tried to use a named capture group. Note also that `\w` already matches the same characters as `\d`. – Wiktor Stribiżew Mar 16 '16 at 08:35
  • An example line that you are running this against would help – urban Mar 16 '16 at 08:41
  • 1
    The error might be due to your placing of `-` in middle `\s-\w`. Place it at beginning or end in character class. –  Mar 16 '16 at 09:12
  • @noob: It seems that Python `re` is really weird, and regex101 has another Python bug. [`regex = re.compile(r'(?P[\w\d:]+)[\s\w\d-]+\[(?P[\w\s:\d-]+)')`](https://ideone.com/2Ag1BW) works. However, `regex` PyPi module can handle the OP regex without any issues. – Wiktor Stribiżew Mar 16 '16 at 09:27
  • @WiktorStribiżew: Didn't knew that. Just guessing. I think OP got the wrong regex for his requirement. I think he is trying to match some device name in format of MAC address. But he is using `[\w\s:\d-]+`. I guess it should had been a group. –  Mar 16 '16 at 09:29

0 Answers0