Snippets Collections
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^\w\s]','',s)
# \w matches any word character (equivalent to [a-zA-Z0-9_])
# \s matches any whitespace character (equivalent to [\r\n\t\f\v ])
//Opción 1:
function getCount(str) {
  const vocal = str.match(/[aeiou]/ig);
  return vocal === null ? 0 : vocal.length; //si no hay vocales devuelve 0, si hay devuelve la cantidad
}

//Opción 2:
function getCount(str) {
  return str.replace(/[^aeiou]/gi, '').length;
}

//Opción 3:
function getCount(str) {
  return (str.match(/[aeiou]/ig)||[]).length;
}
/^(0{0,2}\+?389[\s./-]?)(\(?[0]?[7-7][0-9]\)?[\s./-]?)([2-9]\d{2}[\s./-]?\d{3})$/gm
​"(https:\/\/[\w-]*\.?zoom.us\/(j|my)\/[\d\w?=-]+)"gm
/https:\/\/[\w-]*\.?zoom.us\/(j|my)\/[\d\w?=-]+/gm
window.matchMedia('(min-width: 1100px)').matches 
https:\/\/(.*\.)thesite.com?\/.*
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
$> sudo visudo

www-data ALL=NOPASSWD: /usr/bin/docker

<?php
    echo '<pre>';
    $content = system('sudo docker images', $ret);
    echo '</pre>';
?>

// si se necesita executar exec, hacerlo sin el "-it"
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;
};
https://vimsky.com/zh-tw/examples/detail/python-method-regex.sub.html

# Match text between two strings with regular expression
clean_text = re.search(r'before(.*?)after', text).group(1)
import re
s = 'Part 1. Part 2. Part 3 then more text'
re.search(r'Part 1\.(.*?)Part 3', s).group(1)
' Part 2. '
re.search(r'Part 1(.*?)Part 3', s).group(1)
'. Part 2. '
<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 Nov 12 2023 12:07:18 GMT+0000 (Coordinated Universal Time)

#python #regex
star

Sat May 20 2023 17:27:25 GMT+0000 (Coordinated Universal Time) https://www.codewars.com/users/MeridaK/completed_solutions

#javascript #string #.match() #expresionesregulares #regex
star

Mon May 15 2023 05:44:23 GMT+0000 (Coordinated Universal Time) https://regex101.com/r/Uz4z9c/1

#regex #mobile #macedonia
star

Tue Mar 21 2023 18:27:17 GMT+0000 (Coordinated Universal Time) https://regex101.com/

#regex #python
star

Tue Mar 21 2023 18:20:32 GMT+0000 (Coordinated Universal Time) https://regex101.com/

#regex
star

Thu Feb 23 2023 07:15:26 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.replace?view

#vb.net #regex
star

Thu Feb 23 2023 06:17:10 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.match.groups?view

#vb.net #regex
star

Fri Feb 10 2023 17:01:19 GMT+0000 (Coordinated Universal Time)

#sitewide #regex
star

Thu Feb 09 2023 19:55:06 GMT+0000 (Coordinated Universal Time)

#sitewide #regex
star

Tue Oct 11 2022 01:01:32 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url

#javascript #regex
star

Mon Aug 29 2022 19:07:13 GMT+0000 (Coordinated Universal Time)

#regex
star

Mon Aug 29 2022 19:06:19 GMT+0000 (Coordinated Universal Time)

#regex
star

Mon Aug 29 2022 19:02:16 GMT+0000 (Coordinated Universal Time)

#regex
star

Thu Jul 21 2022 09:20:15 GMT+0000 (Coordinated Universal Time)

#vscode #regex
star

Sun May 29 2022 07:12:48 GMT+0000 (Coordinated Universal Time)

#yup #regex #validation
star

Mon Apr 25 2022 12:37:34 GMT+0000 (Coordinated Universal Time)

#yup #regex #validation
star

Mon Apr 25 2022 12:36:27 GMT+0000 (Coordinated Universal Time)

#yup #regex #validation
star

Mon Apr 25 2022 12:35:41 GMT+0000 (Coordinated Universal Time)

#yup #regex #validation
star

Mon Apr 25 2022 12:33:53 GMT+0000 (Coordinated Universal Time)

#yup #regex #validation
star

Sat Mar 05 2022 16:07:21 GMT+0000 (Coordinated Universal Time) https://regexr.com/

#regex
star

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

#regex #javascript
star

Tue Nov 09 2021 22:47:47 GMT+0000 (Coordinated Universal Time) 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 (Coordinated Universal Time)

#javascript #regex #email
star

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

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

Tue Jul 20 2021 04:01:34 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/32680030/match-text-between-two-strings-with-regular-expression

#python #pandas #regex
star

Wed Jun 16 2021 12:29:04 GMT+0000 (Coordinated Universal Time)

#pattern #regex #htm #password
star

Fri Apr 30 2021 22:00:34 GMT+0000 (Coordinated Universal Time)

#regex
star

Mon Apr 12 2021 12:33:54 GMT+0000 (Coordinated Universal Time)

#regular-expression #regex
star

Sat Mar 27 2021 11:46:04 GMT+0000 (Coordinated Universal Time)

#php #regex
star

Sun Mar 21 2021 08:40:14 GMT+0000 (Coordinated Universal Time)

#python #regex
star

Sat Oct 17 2020 16:34:53 GMT+0000 (Coordinated Universal Time) 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 (Coordinated Universal Time) https://stackoverflow.com/questions/12595051/check-if-string-matches-pattern

#regex #python #match
star

Tue Jul 21 2020 07:06:16 GMT+0000 (Coordinated Universal Time)

#urls #sitemap #regex

Save snippets that work with our extensions

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