-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb98f50
commit b310d62
Showing
1 changed file
with
4 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Use the correct `RegExp` method | ||
|
||
In general terms: | ||
In general: | ||
|
||
- Use `.test` if you want a faster boolean check. | ||
- Use `.match` to retrieve all matches when using the g global flag. | ||
- Use `.test` if you want a fast boolean check. | ||
- Use `.match` to retrieve all matches when using the `g` flag. | ||
|
||
> It's possible that you can gain an extra of perfomance using String method to match `RegExp` instead of RegExp to match String. It's depends of your case of use and of your JavaScript Engine. Check [test#1](https://jsperf.com/regexp-test-search-vs-indexof/12), [test#2](https://jsperf.com/regex-methods-x-1/2) & [test#3](https://jsperf.com/test-vs-indexof-fast/5) benchmarks. | ||
> It is possible to gain extra perfomance using `String` method to match `RegExp` instead of `RegExp` to match `String`. It depends on your use case and of your JavaScript engine. Check [test#1](https://jsperf.com/regexp-test-search-vs-indexof/12), [test#2](https://jsperf.com/regex-methods-x-1/2) and [test#3](https://jsperf.com/test-vs-indexof-fast/5) benchmarks. |