-
Notifications
You must be signed in to change notification settings - Fork 36
Regular Expressions - Cheat Sheet #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bharat13soni
wants to merge
1
commit into
workattech:master
Choose a base branch
from
bharat13soni:Regular-Expressions-Cheat-Sheet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| bharat soni |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Regular Expressions - Cheat Sheet | ||
|
|
||
| * use a single `|` to say 'or' | ||
| * `[ ]` - says any of the characters inside the brackets | ||
| * `?` make the preceding token optional | ||
| * `.+` - matches all characters to the end of the line | ||
| * use parentheses to group characters as using the `|` alone divide the regex into only a left and right side. | ||
| * `^` matches only if it's at the beginning of a string | ||
| * `$` matches only if it's the end of a string | ||
| * `+` is greedy - it won't just get the next token. it will keep searching until it reaches the last one. | ||
| * `+?` is not greedy - it will just search to the next occurrence of a token. | ||
| * `{3}` - would match 3 occurrences of the preceding token | ||
| * `{3,4}` - could match the range of 3 to 4 characters of the preceding token | ||
|
|
||
| ## Flags | ||
| * `\w` - matches any word character | ||
| * `\r` = carriage return | ||
| * `\n` = new lines | ||
| * `\s` = space characters | ||
| * `\w` = word character | ||
| * `\d` = digits 0-9 | ||
|
|
||
| ## Lookahead and Lookbehind | ||
| * `(?<!` = negative look behind | ||
| * `(?<=` = positive look behind | ||
| * `(?=` = positive look ahead | ||
| * `(?!` = negative look ahead | ||
|
|
||
| ## JavaScript Methods | ||
| * `RegExp.exec(string)` = Applies the RegExp to the given string, and returns the match information. | ||
| * `RegExp.test(string)` = Tests if the given string matches the Regexp, and returns true if matching, false if not. | ||
| * `String.match(pattern)` = Matches given string with the RegExp. With g flag returns an array containing the matches, without g flag returns just the first match or if no match is found returns null. | ||
| * `String.search(pattern)` = Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not. | ||
| * `String.replace(pattern,string)` = Replaces matches with the given string, and returns the edited string. | ||
| * `String.split(pattern)` = Cuts a string into an array, making cuts at matches. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good. Please add examples to make it better.