You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/solution.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
In order to insert after the `<body>` tag, we must first find it. We can use the regular expression pattern `pattern:<body.*?>` for that.
2
2
3
-
In this task we don't need to modify the `<body>` tag. We only need to add the text after it.
3
+
In this task, we don't need to modify the `<body>` tag. We only need to add the text after it.
4
4
5
5
Here's how we can do it:
6
6
@@ -27,10 +27,10 @@ As you can see, there's only lookbehind part in this regexp.
27
27
It works like this:
28
28
- At every position in the text.
29
29
- Check if it's preceded by `pattern:<body.*?>`.
30
-
- If it's so then we have the match.
30
+
- If it's so, then we have the match.
31
31
32
-
The tag `pattern:<body.*?>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:<body.*?>`.
32
+
The tag `pattern:<body.*?>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceded by `pattern:<body.*?>`.
33
33
34
-
So it replaces the "empty line", preceeded by `pattern:<body.*?>`, with `<h1>Hello</h1>`. That's the insertion after `<body>`.
34
+
So it replaces the "empty line", preceded by `pattern:<body.*?>`, with `<h1>Hello</h1>`. That's the insertion after `<body>`.
35
35
36
36
P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also be useful: `pattern:/<body.*?>/si`. The `pattern:s` flag makes the dot `pattern:.` match a newline character, and `pattern:i` flag makes `pattern:<body>` also match `match:<BODY>` case-insensitively.
0 commit comments