Define a group in regex

2

I'm testing the following regex:

(?i)(\s|\W|)(fire|fire-type)(\s|\W)

I have 2 problems:

1st case (SOLVED) has only one word without spaces at the beginning or end my regex does not catch. Ex:

fire

In my group I have a fire-type but regex takes only the fire and igonara the -type . Does anyone know how I can resolve these 2 cases?

    
asked by anonymous 15.12.2016 / 16:47

1 answer

5

Normally in regular expressions the hyphen - is a sequence indicator, for example, instead of writing [abcdefgh] , we write, [a-h] . Or you are case-sensitive with [a-hA-H] .

In this way the hyphen is a character used to define sequences in regular expressions, if you want to find a text with the hyphen, we should warn the regex that they should be understood as literal by preceding them with an escape sign \ ), below are some commonly used examples:

\- (faz a busca pelo "-")
\] (faz a busca pelo "]")
\ (faz a busca pelo "\")
    
15.12.2016 / 18:41