regEx
Quantifiers
Metacharacters
Groups
flags
/abdul/ | A regular expression |
---|---|
/abdul/i | A case-insensitive regular expression |
/g | Perform a global match (find all) |
/i | Perform case-insensitive matching |
/m | Perform multiline matching |
var pattern = /abdul/
text.match(pattern)
---------------------------------------------------------------------
let text = "aaaabb";
let result = text.match(/(aa)(bb)/d);
---------------------------------------------------------------------------
let text = `Is this
all there
is`
let pattern = /^is/m;
let result = text.match(pattern);
-------------------------------------------------------------------------
The "m" modifier specifies a multiline match.
It only affects the behavior of start ^ and end $.
^ specifies a match at the start of a string.
$ specifies a match at the end of a string.
With the "m" set, ^ and $ also match at the beginning and end of each line.
<p>Do a global, case-insensitive, multiline search for "is" at the beginning of each line in a string.</p>
let text = `Is this
all there
is`
let pattern = /^is/gmi;
-------------------------------------------------------------------------------------------------
<p>The multiline property returns true if the "m" modifier is set, otherwise false:</p>
<p id="demo"></p>
<script>
let text = "Visit W3Schools!";
let pattern = /W3S/gmi;
let result = pattern.multiline;
-------------------------------------------------------------------------------------------------
Regular Expression Search Methods
text.match(pattern) | The String method match() |
text.search(pattern) | The String method search() |
pattern.exec(text) | The RexExp method exec() |
pattern.test(text) | The RegExp method test() |
search() searches a string for a value and returns the position of the first match
match() searches for a match in a string
The test() method returns true if it finds a match, otherwise false.
The exec() method tests for a match in a string
0 comments:
Post a Comment