0

I have three string samples below:

day/Mon/done
day/Tue/done
day/Wed/done

How do I extract day/Wed/done using negation for the other two? Below doesn't work.

/day/[^(Mon|Tue)]/done
adizone
  • 153
  • 2
  • 11

2 Answers2

1

It's not how negated character classes work -- they still interpret each character inside the [..] as a single character. And there is no match for

day/?/done

where ? is only one character. Either use any of the techniques in Regular expression to match a line that doesn't contain a word? (thanks, Peter!), or make good use of the fact that the first character for these days are unique:

day/[^MT]../done
Community
  • 1
  • 1
Jongware
  • 21,058
  • 8
  • 43
  • 86
1

You might try lookahead.

'day/(?!(Mon|Tue)).*/done'
plafratt
  • 598
  • 8
  • 13