Skip to content

Commit

Permalink
Update Javascript RegExp.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf authored Nov 8, 2023
1 parent de510fd commit 6518b7d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/Javascript Examples/Javascript RegExp.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ string for the entire match and one for each capture group.

If a pattern doesn't match null is returned.

## Named Capture Groups

For more complex expressions name captures for better code:

var results = "some.person@example.com".match(/(?<name>.+)@(?<domain>.+)/);
console.log(results.groups[name]); # Gives "some.person"
console.log(results.groups[domain]); # Gives "example.com"

## Replacing Patterns

To replace substrings by pattern just pass a regular expression to String.replace()
Expand All @@ -41,3 +49,7 @@ To reuse expressions assign them to a variable or explicitely create an RegExp o

var re = /abc/;
var re = new RegExp("abc");

and use it

"abcdef".match(re);

0 comments on commit 6518b7d

Please sign in to comment.