Clarifiy regex in docs

Open
#28 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
58/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript, php
Domain
documentation

Research direction

Read the regex matcher documentation and compare its examples with the new RegExp() behavior described in the issue. Clarify whether regex values need delimiters and how the examples are interpreted; the issue says a proposed matcher change belongs in the bundle repository. Done when the docs explain the current behavior clearly and address the ambiguity raised in the examples.

Written by the indexing model from the issue text.

Description

At first, I thought the regex documentation was wrong, and started to fix it:

| regex | Matches the regex |

  • regex: |/image/.*|
  • regex: {.jp(e)?g$}i
|

Although slash is a common character to use to enclose a regular expression, the examples above show using other characters to avoid needing to escape the slashes in the path. So //articles/./ is the same regex as {/articles/.}. See Regular Expressions for more information. Internally, regeg: maps to new RegExp()

But then when I dug into the code, I see that the new RegExp() format doesn't need the regex to be surrounded. I think this needs to be clearer, especially since when I see something like this:

startsWith: /dashboard
regex: /articles/
regex: |/articles/(\d)+|  # is this valid?

I assume the regex will match any article (without the slashes, since to PHP programmers it will be natural to assume the slashes are necessary for the regex.

workbox.routing.registerRoute(
  new RegExp('{^/products|categories/}')

At the end of my journey down regex lane, here's my trip report:

  • the code currently generates new RegExp('$regexString'), which isn't intuitive to PHP programmers and excludes the ability to use flags.
  • Instead, I think it should generate the regex string itself, which is javascript, e.g. workbox.routing.registerRoute(/products|categories/, ...
  • We could have another matcher, RegExp: that generates what the code currently does, and regex: that generates a javascript regex.

Regardless, the docs should be updated. I'll move my suggestion to an issue in the bundle repo.

Dominant language
Python
Stars
0
Forks
0
Avg merge
34m
Merged PRs (30d)
40

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Spomky-Labs/docs

All issues in Spomky-Labs/docs

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.