Snippets Collections
password: Yup.string()
          .required('Please Enter your password')
          .matches(
            /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})/,
            "Must Contain 8 Characters, One Uppercase, One Lowercase, One Number and One Special 			 			Case Character"),
            passwordConfirmation: Yup.string().oneOf(
              [Yup.ref("password"), null],
              "Passwords must match"
            ),
phone:yup
.string()
.min(11, "شماره وارد شده صحیح نیست")
.required("تلفن را وارد کنید")
.matches(/^[09].[0-9]{9}$/, "شماره تلفن خود را به درستی وارد کنید ")
username: yup
.string()
.min(3, "نام کاربری از 3 حرف کمتر نباشد")
.required("نام کاربری را وارد کنید")
.matches(
/^[A-za-zآابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+/,
"نام کاربری را به درستی وارد کنید"
)
email: yup
.string()
.required("ایمیل را وارد کنید")
.matches(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\. [0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
        )
national_code: yup
      .string()
      .required("لطفا کد ملی خود را وارد کنید")
      .test("nationalCodeValid", "فرمت کد ملی صحیح نمی باشد", function (value) {
        if (!/^\d{10}$/.test(value)) return false;
        const check = +value[9];
        const sum =
          value
            .split("")
            .slice(0, 9)
            .reduce((acc, x, i) => acc + +x * (10 - i), 0) % 11;
        return sum < 2 ? check === sum : check + sum === 11;
      })
/* No-index posts older than 90 days if in PR custom post type */

function noindexOldPRs() {
	$url = 'http://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
	$current_post_id = url_to_postid( $url );
	
	$publishdate = get_the_time('Y-m-d', $current_post_id);
	$posttype = get_post_type ($current_post_id);
	
	if ($posttype == "pr") {
		$ninetydaysago = date("Y-m-d", strtotime("-90 days"));
		if($publishdate < $ninetydaysago) {
			echo '<meta name="robots" content="noindex">';
		}
	} elseif (has_tag('nonnews', $current_post_id)) {
		echo '<meta name="Googlebot-News" content="noindex, nofollow">';
	}
	
	//add noindex/nofollow for google news bot
	// get tags
	// if a tag includes nonnews
	// then add
	// <meta name="Googlebot-News" content="noindex, nofollow">

}
add_action('wp_head', 'noindexOldPRs');
wp search-replace '<script async\s*.*>\s*.*<\/script>' '' wp_posts --regex --allow-root
const validateEmail = email => {
    const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return regex.test(String(email).toLowerCase());
  }
// SOLUTION 1 - MY (DISCOVERED) SOLUTION (RUNTIME - 104MS, 44.9 MB)
var isAnagram = function(s, t) {
    
    // set function to split, sort, and rejoin characters in a string
    const sortString = (str) => {
        return str.split("").sort().join("");
    }
    
    // regex removes any non-alphabet characters in the string and makes it lowercase
    s = s.replace(/[^\w]/g, '').toLowerCase()
    t = t.replace(/[^\w]/g, '').toLowerCase()

    // final comparison
    return sortString(s) === sortString(t)
  
  // ATTEMPT 1
  //     let anagram = []
    
  // return false is lengths don't match
  //     if (s.length !== t.length) return false;
  //     else {
  //         for (let i = 0; i < s.length; i++) {
  //             let arrT = t.split("")
  //             let newArrT;
  //             if (arrT.includes(s.charAt(i))) {
  //                 let index = arrT.indexOf(s.charAt(i));
  //                 console.log("s char: ", s.charAt(i));
  //                 console.log("index: ", index);

  //                 anagram.push(s.charAt(i))

  //                 console.log("splice: ", arrT.splice(index, 1))
  //                 arrT.splice(index, 0)

  //                 newArrT = arrT
  //                 console.log("newArr: ", newArrT)
  //             };
  //         };
  //     }
  //     console.log(anagram)
  //     return anagram.join("") === s;
}

// SOLTUION 2 - (BEST RUNTIME - 60MS)
var isAnagram = function(s, t) {
    const key = w => Object.entries([...w].reduce((a, c) => {
        if (!(c in a)) a[c] = 0;
        a[c] += 1;
      
        return a;
    }, {})).sort(([c1], [c2]) => c1.localeCompare(c2)).flat().join('');
  
    return key(s) === key(t);
};

// SOLUTION 3 - (RUNTIME - 72MS)
var isAnagram = function(s, t) {
    if(s.length !== t.length) return false;
  
    let map = {};
  
    for(let item of s) {
        map[item] = map[item] + 1 || 1;
    }
    
    for(let item of t) {
        if(!map[item]) return false;
        else map[item]--;
    }
  
    return true;
};
<label
					aria-label="password"
					class="form-label"
					for="password"
				>Password</label>
				<p><small>6 - 12 characters, one number, one symbol, one uppercase and
						one lowercase letter.</small></p>
				<input
					class="form-control"
					title="Must be 6 - 12 characters and contain at least one number, one symbol, one uppercase and one lowercase letter."
					type="password"
					id="password"
					name="password"
					required
					pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{6,12}$"
				/>
(\w+)
to
"$1",
  
ASD
ZXC
  
to
  
"ASD",
"ZXC",
preg_match('/(.)\\1{4,}/', $text)
import re

print(re.search(r"[Pp]ython", "Python"))
print(re.search(r"[a-z]way", "The end of the highway"))
print(re.search(r"cloud[a-zA-Z0-9]", "cloudy"))

# put ^ before a character class to search for anything but the given character class
print(re.search(r"[^a-zA-Z]", "This is a sentence with spaces."))

# | as OR operator
print(re.search(r"cat|dog", "I like dogs."))
print(re.findall(r"cat|dog", "I like both cats and dogs."))
import re 
s = "string. With. Punctuation?" 
s = re.sub(r'[^\w\s]','',s) 
import re
if re.match(r"hello[0-9]+", 'hello1'):
    print('Yes')
((<url>)\n(<loc>))|((<\/loc>)\n.*\n.*\n.*\n(<\/url>))
star

Sun May 29 2022 07:12:48 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:37:34 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:36:27 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:35:41 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:33:53 GMT+0000 (UTC)

#yup #regex #validation
star

Wed Dec 22 2021 20:24:34 GMT+0000 (UTC) https://regex101.com/r/FiVZGX/1/

#regex #javascript
star

Tue Nov 09 2021 22:47:47 GMT+0000 (UTC) https://stackoverflow.com/questions/16699007/regular-expression-to-match-standard-10-digit-phone-number

#regex #phone
star

Thu Oct 14 2021 19:02:39 GMT+0000 (UTC)

#javascript #regex #email
star

Tue Sep 21 2021 14:51:47 GMT+0000 (UTC) https://leetcode.com/submissions/detail/558649741/?from=explore&item_id=882

#javascript #strings #regex #sort #anagram #loops #unsolved
star

Fri Apr 30 2021 22:00:34 GMT+0000 (UTC)

#regex
star

Sat Mar 27 2021 11:46:04 GMT+0000 (UTC)

#php #regex
star

Sun Mar 21 2021 08:40:14 GMT+0000 (UTC)

#python #regex
star

Sat Oct 17 2020 16:34:53 GMT+0000 (UTC) https://www.quora.com/How-do-I-remove-punctuation-from-a-Python-string

#python #regex #punctuation
star

Wed Aug 12 2020 03:09:20 GMT+0000 (UTC) https://stackoverflow.com/questions/12595051/check-if-string-matches-pattern

#regex #python #match
star

Tue Jul 21 2020 07:06:16 GMT+0000 (UTC)

#urls #sitemap #regex

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension