Skip to content

Commit d46a777

Browse files
authored
Apply suggestions from code review
1 parent acd12fe commit d46a777

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

files/en-us/web/api/url_pattern_api/index.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ console.log(pattern4.test("https://example.com/#hash")); // true
155155

156156
#### Lookahead and lookbehind assertions
157157

158-
Lookahead and lookbehind asserts allow you to specify that text ahead or behind the current parsing position matches a particular pattern, without that match being captured, or the characters being consumed.
158+
[Lookahead](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion) and [lookbehind](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion) asserts allow you to specify that text ahead or behind the current parsing position matches a particular pattern, without that match being captured, or the characters being consumed.
159159

160160
There are four types of assertions:
161161

162-
- `(?=...)`: A positive lookahead assertion specifies a pattern than the following characters must match.
163-
- `(?!...)`: A negative lookahead assertion specifies a pattern than the following characters must not match.
164-
- `(?<=...)`: A positive lookbehind assertion specifies a pattern than the preceding characters must match.
165-
- `(?<!...)`: A negative lookbehind assertion specifies a pattern than the preceding characters must not match.
162+
- `(?=...)`: A positive lookahead assertion specifies a pattern that the following characters must match.
163+
- `(?!...)`: A negative lookahead assertion specifies a pattern that the following characters must not match.
164+
- `(?<=...)`: A positive lookbehind assertion specifies a pattern that the preceding characters must match.
165+
- `(?<!...)`: A negative lookbehind assertion specifies a pattern that the preceding characters must not match.
166166

167-
Lookahead and lookbehind assertions do not match intuitively.
167+
Be careful when using lookahead and lookbehind assertions with `URLPattern`, as there is some behavior you may find unintuitive.
168168
For example, you would expect the following lookahead assertion to match a `pathname` of `/ab`, but this is not what happens.
169169

170170
```js example-bad
@@ -406,10 +406,10 @@ console.log(patternOptionalSlash.test("https://example.com/books/")); // true
406406
### Pattern normalization
407407

408408
When a pattern is parsed it is automatically normalized to a canonical form.
409-
For example, Unicode characters are percent encoded in the pathname property, punycode encoding is used in the hostname, default port numbers are elided, paths like `/foo/./bar/` are collapsed to just `/foo/bar`, etc.
409+
For example, Unicode characters are [percent-encoded](/en-US/docs/Glossary/Percent-encoding) in the pathname property, punycode encoding is used in the hostname, default port numbers are elided, paths like `/foo/./bar/` are collapsed to `/foo/bar`, etc.
410410
In addition, there are some pattern representations that parse to the same underlying meaning, like `foo` and `{foo}`.
411411
Such cases are normalized to the simplest form.
412-
In this case `{foo}` gets changed to `foo`.
412+
In this case `{foo}` is normalized to `foo`, for example.
413413

414414
## Inheritance from a base URL
415415

@@ -632,9 +632,9 @@ try {
632632

633633
The following example shows how input values that match pattern groups can later be accessed from the {{domxref("URLPattern/exec","exec()")}} result object.
634634

635-
The `input` property is the string that is matched by the pattern: in this case`cdn.example.com`.
635+
The `input` property is the string that is matched by the pattern: in this case it's `cdn.example.com`.
636636
The `groups` property contains captured groups, indexed by number for unnamed groups, and name for named groups.
637-
In this case there is just one unnamed group for the wildcard property, with the value `cdn`.
637+
In this case, there is only one unnamed group for the wildcard property, with the value `cdn`.
638638

639639
```js
640640
const pattern = new URLPattern({ hostname: "*.example.com" });

files/en-us/web/api/urlpattern/exec/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The object has the following properties:
5050
Each property contains an object with the following properties:
5151
- `input`
5252
- : The part of the input corresponding to the current URL-part property (which must have matched the pattern).
53-
This might be the empty string ("").
53+
This might be the empty string (`""`).
5454
- `groups`
5555
- : An object with properties for each match group in the URL part (if any), and the corresponding matched values in the inputs.
5656
The group properties are numbered from 0 for unnamed match groups (such as the wildcard).

files/en-us/web/api/urlpattern/port/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This pattern matches any URL that has the port `80`, `443`, or `8080`.
2929
```js
3030
const pattern = new URLPattern({ port: "(80|443|8080)" });
3131
console.log(pattern.port); // "(80|443|8080)"
32+
console.log(pattern.test("http://example.com:8080/")); // true
3233
```
3334

3435
## Specifications

files/en-us/web/api/urlpattern/username/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This pattern matches only if the username part of the URL is `admin`.
2626
```js
2727
const pattern = new URLPattern({ username: "admin" });
2828
console.log(pattern.username); // "admin"
29+
console.log(pattern.test("http://admin:[email protected]/")); // true
2930
```
3031

3132
## Specifications

0 commit comments

Comments
 (0)