Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route method regex explained #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion session-07/S07-Vanilla-PHP-MVC-Pt-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ if (count($uriSegments) === count($routeSegments) && strtoupper($route['method']
$match = false;
break;
}

// /is the start and end of regex pattern
// \escapes the curly brace, making it a regular character, it's looking for it.
// parenthesis is the capturing group
// . is any character that is not a newline
// + is one or more proceeding elements
// ? lazy making match as few characters as possible
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Consider condensing the regex explanation comments

While the detailed explanation is helpful, it might be more concise to combine some of these comments. For example: '// / marks regex start/end, \ escapes {, (.+?) captures any chars (non-greedy)'

Suggested change
// /is the start and end of regex pattern
// \escapes the curly brace, making it a regular character, it's looking for it.
// parenthesis is the capturing group
// . is any character that is not a newline
// + is one or more proceeding elements
// ? lazy making match as few characters as possible
// / marks regex start/end, \ escapes {, (.+?) captures any chars (non-greedy)
// () is capturing group, . any char except newline, + one or more, ? lazy match

if (preg_match('/\{(.+?)}/', $routeSegments[$i], $matches)) {
$params[$matches[1]] = $uriSegments[$i];
}
Expand Down