RegExp#exec
and String#match
JS-D00710241 updateKey = response.url.match(/[?|&]update=([^&]+)($|&)/)
10242 ? RegExp.$1
10243 : null;
10244 addElement = response.url.match(/[?|&]add_element=([^&]+)($|&)/)10245 ? RegExp.$1
10246 : null;
10247 $(".webform-ajax-refresh").trigger("click");
10238 a.pathname === window.location.pathname &&
10239 $(".webform-ajax-refresh").length
10240 ) {
10241 updateKey = response.url.match(/[?|&]update=([^&]+)($|&)/)10242 ? RegExp.$1
10243 : null;
10244 addElement = response.url.match(/[?|&]add_element=([^&]+)($|&)/)
10225 // @see https://stackoverflow.com/questions/6944744/javascript-get-portion-of-url-path
10226 var a = document.createElement("a");
10227 a.href = response.url;
10228 var forceReload = response.url.match(/\?reload=([^&]+)($|&)/)10229 ? RegExp.$1
10230 : null;
10231 if (forceReload) {
10738 updateKey = response.url.match(/[?|&]update=([^&]+)($|&)/)
10739 ? RegExp.$1
10740 : null;
10741 addElement = response.url.match(/[?|&]add_element=([^&]+)($|&)/)10742 ? RegExp.$1
10743 : null;
10744 $(".webform-ajax-refresh").trigger("click");
10735 a.pathname === window.location.pathname &&
10736 $(".webform-ajax-refresh").length
10737 ) {
10738 updateKey = response.url.match(/[?|&]update=([^&]+)($|&)/)10739 ? RegExp.$1
10740 : null;
10741 addElement = response.url.match(/[?|&]add_element=([^&]+)($|&)/)
RegExp#exec
and String#match
should only be used when we need to use the parts of a string that match a specific pattern:
const matches = /[a-zA-Z0-9]+/.exec(string)
for (const match of matches) {
processMatch(match)
}
If you only want to know whether a string matches a particular pattern, RegExp#test
is a faster alternative.
const matches = str.match(/[a-zA-Z0-9]/) ? process(str) : process("default-str");
const strMatchesPattern = !!str.match(/regex/)
const regexp = new RegExp("[a-zA-Z0-9]*")
if (regexp.exec(myString)) {
// ...
}
const matches = '/hasTheMagic/'.test(str) ? process(str) : process("default-str");
const strMatchesPattern = /regex/.test(str)
const regexp = new RegExp("[a-zA-Z0-9]*")
if (regexp.test(myString)) {
// ...
}