I've been trying to find out what this code means but I haven't had any luck even finding out where to start or what to look up.
if(!/^(https?):\/\//i.test(value))
I understand some of it so I've got the following questions.
If this appears to be a question without research, any guidance where to start would be great.
A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.
The Match-zero-or-more Operator ( * ) This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. `*' represents this operator. For example, `o*' matches any string made up of zero or more `o' s.
I prefer "re", but it depends on the language. JavaScript lists it as "RegExp", whereas most other languages just call it "RegEx."
A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs.
A regular expression is an object that describes a pattern of characters.
Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.
This is exactly the same but maybe more clear
var patt = /^(https?):\/\//i;
if( !patt.test(value) ){
// value DOES NOT MATCH patt!
}
In this case it checks that value
doesn't start with http://
or https://
/ //Open regexp
^ //Start of the string
( // Start of the capturing group
https? //Match literally http or https (because s is optional "?")
) // End of capturing group
:\/\/ // Match literally ://
/ // Close regexp
i // Case-insensitive flag
Might this help you
^
assert position at start of the string http
matches the characters http literally (case insensitive)s?
matches the character s literally (case insensitive)?
Between zero and one time, as many times as possible, giving back as needed [greedy]:
matches the character : literally\/
matches the character / literallyi
modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With