Skip to content

Commit c285712

Browse files
Merge pull request #10 from chastabor/master
example use case where dot matches newline
2 parents 6e83799 + 51994f3 commit c285712

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

01-chapter2.markdown

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,35 @@ Now using the the (?s) flag, the newline is kept in the result.
247247
// ar an as al ab am a
248248
// ar ac]>
249249

250+
Clear out multi-line comments in css file
251+
252+
s := `/* multi line
253+
comment with
254+
url("http://commented1.test.com/img.jpg") */
255+
body {
256+
background: #ffffff url("actual1.png") no-repeat right top;
257+
}
258+
/* single line commented out url("http://commented2.test.com/img.jpg") *//* back to back comment */
259+
.test-img {
260+
background-image: url("http://test.com/actual2.png");
261+
}`
262+
263+
re := regexp.MustCompile(`(?s)(?:/\*.*?\*/)?((?:[^/]|/[^*])*)`)
264+
results := re.FindAllStringSubmatch(s, -1)
265+
for _, v := range results {
266+
if v[1] != "" {
267+
fmt.Printf("%s", v[1])
268+
}
269+
}
270+
// Prints
271+
// body {
272+
// background: #ffffff url("actual1.png") no-repeat right top;
273+
// }
274+
//
275+
// .test-img {
276+
// background-image: url("http://test.com/actual2.png");
277+
// }
278+
250279
## Shall ^/$ Match at a Newline? ##
251280

252281
When we have a multiline string you can control

0 commit comments

Comments
 (0)