1

I work for a news outlet and would like to filter for URLs containing several dates. Each date would have more than one URL associated. For example I would like a filter that catches all of these:

  • /2019/03/01/here-is-a-post-title
  • /2019/03/01/here-is-a-different-post-title
  • /2019/03/02/here-is-a-post-title-as-well
  • /2019/03/03/here-is-yet-another-post-title
  • /2019/03/03/here-is-post-title
  • /2019/03/03/a-post-title

The problem is there are many more than there are listed above. And, for example, what I want to do is filter for all page URLs that begin with:

/2019/03/01/ OR /2019/03/02/ OR /2019/03/03/

I believe this ^/2019/03/01/$|^/2019/03/02/$|^/2019/03/03/$ doesn't work with page "Matching RegExp", "Beginning", or "Containing" because there is more in the URL following the last "/" in each URL query. So how would I go about doing this?

2

Your regular expression is pretty close if you remove the $s. Those means "ends with," which isn't what you want.

I'd take the approach of having a single "starts with slash" (^/) followed by your dates with parenthesis for grouping, and explicitly say it can end with anything (.* ):

^/((2019/03/01)|(2019/03/02)|(2019/03/03))/.*

That should work with "Matching RegExp" just fine. For your specific dates, you could simplify it. Those dates only differ on the last digit. So this regex would be the same. [123] means exactly one of any of those three digits.

^/2019/03/0[123]/.*

You could even combine that simplification with other dates. For example if you wanted Feb 28 and the first three dates in March:

^/((2019/02/28)|(2019/03/0[123]))/.*

Or if you wanted the last day of January, all of February, and the first three days of March:

^/((2019/01/31)|(2019/02)|(2019/03/0[123]))/.*

If it is all in the same year, you could again simplify by putting the year with the starting slash:

^/2019/((01/31)|(02)|(03/0[123]))/.*

I think that is enough examples that you can build a good regular expression with the actual dates you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.