'regex - dash symbol match

I'm trying to match the "-" symbol

https://regex101.com/r/7NuWBy/1

([0-9]+) (Cat) · ([0-9]+) (Dog) · ([0-9]+) (Fish)

This is the text

134 Cat · 13 Dog · — Fish
14 Cat · 133 Dog · 1 Fish
124 Cat · 1333 Dog · 32 Fish


Solution 1:[1]

First, you should not use a . directly instead use \.
because a . means any character except a newline \n
so the correct regex would be:

([0-9]+|-) (Cat) \· ([0-9]+|-) (Dog) \· ([0-9]+|-) (Fish)

Solution 2:[2]

Converting my comment to answer so that solution is easy to find for future visitors.

Your desired regex must include hyphen also since you want to match substrings that include hyphens as well. Your intended regex would be:

([0-9—]+) (Cat) \· ([0-9—]+) (Dog) \· ([0-9—]+) (Fish)

A dot has a special meaning and it must also be escaped to avoid matching just any character.

Updated Regex Demo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user16714199
Solution 2 anubhava