JavaScript RegExp test() পদ্ধতি
- পূর্ববর্তী পৃষ্ঠা
- পরবর্তী পৃষ্ঠা
- একত্রিভূমি ফিরে যান JavaScript RegExp রেফারেন্স হান্ডবুক
সংজ্ঞা ও ব্যবহার
test()
মথদলের মিল পাওয়া যায়
যদি মিল পাওয়া যায়, তবে ফিরিয়ে দিয়ে যাওয়া true
, otherwise return false
.
উদাহরণ
উদাহরণ ১
Search for the character "e" in the string:
let text = "The best things in life are free"; let pattern = /e/; let result = pattern.test(text);
Example 2
Perform a global search and test "Hello" and "W3School" in the string:
// String: let text = "Hello world!"; // Find "Hello" let pattern1 = /Hello/g; let result1 = pattern1.test(text); // Find "W3School" let pattern2 = /W3School/g; let result2 = pattern2.test(text);
syntax
regexp.test(string)
parameter
parameter | description |
---|---|
string | required. The string to be searched. |
return value
type | description |
---|---|
Boolean | If a match is found, return true, otherwise return false. |
technical details
return value
if the string string if the string contains regexp matching text, then return true
, otherwise return false
.
throw
type | description |
---|---|
TypeError | Throw this exception if the object called this method is not RegExp. |
description
RegExp object's test()
method checks if the string matches a certain pattern.
The test() method will check if the string string, see if it contains regexp matching text. If string if the string contains such text, this method will return true
, otherwise, return false
.
Call the test() method of the RegExp object r and pass the string s to it, which is equivalent to: (r.exec(s) != null).
browser support
test()
is ECMAScript1 (ES1) feature.
All browsers fully support ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
support | support | support | support | support | support |
Regular expression search methods
In JavaScript, regular expression text search can be completed using different methods.
usepattern (pattern)As regular expressions, these are the most commonly used methods:
example | description |
---|---|
text.match(pattern) | string method match() |
text.search(pattern) | string method search() |
pattern.exec(text) | RexExp পদ্ধতি exec() |
pattern.test(text) | RexExp পদ্ধতি test() |
- পূর্ববর্তী পৃষ্ঠা
- পরবর্তী পৃষ্ঠা
- একত্রিভূমি ফিরে যান JavaScript RegExp রেফারেন্স হান্ডবুক