jQuery selector regular expressions

You can use the filter function to apply more complicated regex matching. Here’s an example which would just match the first three divs: $(‘div’) .filter(function() { return this.id.match(/abc+d/); }) .html(“Matched!”); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <div id=”abcd”>Not matched</div> <div id=”abccd”>Not matched</div> <div id=”abcccd”>Not matched</div> <div id=”abd”>Not matched</div>

Escape string for use in Javascript regex [duplicate]

Short ‘n Sweet (Updated 2021) To escape the RegExp itself: function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, ‘\\$&’); // $& means the whole matched string } To escape a replacement string: function escapeReplacement(string) { return string.replace(/\$/g, ‘$$$$’); } Example All escaped RegExp characters: escapeRegExp(“All of these should be escaped: \ ^ $ * + ? . ( … Read more

What is a good regular expression to match a URL? [duplicate]

Regex if you want to ensure URL starts with HTTP/HTTPS: https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) If you do not require HTTP protocol: [-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) To try this out see http://regexr.com?37i6s, or for a version which is less restrictive http://regexr.com/3e6m0. Example JavaScript implementation: var expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; var regex = new RegExp(expression); var t=”www.google.com”; if (t.match(regex)) { alert(“Successful match”); } else … Read more

How do I split a string with multiple separators in JavaScript?

Pass in a regexp as the parameter: js> “Hello awesome, world!”.split(/[\s,]+/) Hello,awesome,world! Edited to add: You can get the last element by selecting the length of the array minus 1: >>> bits = “Hello awesome, world!”.split(/[\s,]+/) [“Hello”, “awesome”, “world!”] >>> bit = bits[bits.length – 1] “world!” … and if the pattern doesn’t match: >>> bits … Read more

How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

Regular expressions are used for Pattern Matching. To use in Excel follow these steps: Step 1: Add VBA reference to “Microsoft VBScript Regular Expressions 5.5” Select “Developer” tab (I don’t have this tab what do I do?) Select “Visual Basic” icon from ‘Code’ ribbon section In “Microsoft Visual Basic for Applications” window select “Tools” from … Read more

What do ‘lazy’ and ‘greedy’ mean in the context of regular expressions?

Greedy will consume as much as possible. From http://www.regular-expressions.info/repeat.html we see the example of trying to match HTML tags with <.+>. Suppose you have the following: <em>Hello World</em> You may think that <.+> (. means any non newline character and + means one or more) would only match the <em> and the </em>, when in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)