Reduce Fatty Expression

3

I have the following expression:

/((segunda|terça|quarta|quinta|sexta|sábado|domingo)+(((-feira)?)+(.)+\(([0-9].*)\))?)/im

In which you bring me

  

Show Barter performs this Saturday at CDL Theater

RESULTADO: sábado
  

Rock bands perform this Friday (5) in space Marcus Moraes

RESULTADO: sexta (5), sexta, 5, etc.
  

Interior decoration opens new space on Tuesday (15)

RESULTADO: terça-feira (15), terça, -feira (15), 15 etc.

How do I make this expression less 'greedy'?

    
asked by anonymous 18.07.2014 / 03:45

2 answers

2

I believe this is the best (and simplified) expression for your case. Remember that not just a regular expression has to be efficient but easy to understand.

/(((segunda|terça|quarta|quinta|sexta)(-feira)?)|sábado|domingo)(\s*\(\d+\))?/g

Works with:

segunda
terça
quarta
quinta
sexta
sábado
domingo
segunda-feira
terça-feira
quarta-feira
quinta-feira
sexta-feira
segunda (25)
terça (26)
quarta (27)
quinta (28)
sexta (29)
sábado (30)
domingo (31)
segunda-feira (1)
terça-feira (2)
quarta-feira (3)
quinta-feira (4)
sexta-feira (5)

Does not work with:

sábado-feira
domingo-feira
sábado-feita (6)
domingo-feira (7)
-feira
-feira (8)

Link to regexr: link

    
02.09.2014 / 14:05
0

I've simplified my expression a bit to take only the inner groups. I do not know if the goal is to get an empress by phrase, but what I got was this:

(segunda|terça|quarta|quinta|sexta|sábado|domingo)+((-feira)?(.)+\(([0-9]{1,2})\))?
    
18.07.2014 / 04:25