Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 2, 2021
1 parent 9aada84 commit d2551de
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Tests/RegexTests/RegexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,18 @@ final class RegexTests: XCTestCase {
XCTAssertTrue(Regex(#"^foo\d+$"#) ~= "foo123")
XCTAssertTrue("foo123" ~= Regex(#"^foo\d+$"#))
}

func testMultilineOption() {
let regex = Regex(
#"""
^
[a-z]+ # Match the word
\d+ # Match the number
$
"""#,
options: .allowCommentsAndWhitespace
)

XCTAssertTrue(regex.isMatched(by: "foo123"))
}
}
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ default:
}
```

Multiline and comments:

```swift
let regex = Regex(
#"""
^
[a-z]+ # Match the word
\d+ # Match the number
$
"""#,
options: .allowCommentsAndWhitespace
)

regex.isMatched(by: "foo123")
//=> true
```

## API

[See the API docs.](https://sindresorhus.com/Regex/Structs/Regex.html)
Expand Down

0 comments on commit d2551de

Please sign in to comment.