Tag: regex

javascript: getting email address' text in between @ and the dot

Here’s an email: mynick@myemail.com I need to store in a variable: myemail To do so, I’m doing: <script> var email = “mynick@myemail.com”; justMyemail = email.replace(/.*\@|\./gi,”); alert(justMyemail); </script> But the alert shows: myemailcom instead of myemail What is wrong with the code? How can I fix it? Thanks a lot

Search a word using regular expression

How to search a word in exact match, for example how to search word ‘leak‘, but search results should not include words like ‘leaked‘ or ‘leaks‘ etc. Help in both Javascript and MySQL would be appreciated.

Split variable-value in a regex

I’m using Javascript regex functions to split expressions like: var1=32 var2<var4 var1!=var3 I’m using this regex: /^(.*)([=|!=|<|>])(.*)$/ig It works pretty well except with the != (different) operator. What’s the problem?

regex slightly greedy capture?

I have the following possibilities: ‘ !This is a string! ‘ ‘!This is a string !’ ‘! This is a string !’ ‘ ! This is a string! ‘ ‘ ! This is a string ‘ In all of these case I want to match ‘This is a string’ Heres what I tried so far: […]

How to make a simple jQuery filter list accept only whole words, so it doesn't match partial words, only whole words

http://jsfiddle.net/nicktheandroid/U8T8p/4/ (function($) { $(‘.filterinput’).keyup(function() { var filter = $(this).val(); if (filter.length > 2) { // this finds all links in the list that contain the input, // and hide the ones not containing the input while showing the ones that do $(list).find(“a:not(:Contains(” + filter + “))”).parent().slideUp(); $(list).find(“a:Contains(” + filter + “)”).parent().slideDown(); } else { $(list).find(“li”).slideDown(); […]

Where can I find documentation for Javascript's `string.replace(RegExp, function)` method?

Javascript has an overload for string.replace(…) that takes a Regular Expression and a callback function, but I’m having a very difficult time finding ANY documentation on this specific overload! W3Schools.com doesn’t mention this overload. I’ve also gone through dozens of Google results, but every page talks about string.replace(string, string) or string.replace(RegExp, string). It’s almost embarrassing […]

Choose any symbol in javascript regex

I have a string containing something like this “… /*start anythingCanBeEnteredHere end*/ …” I need a regex that gets only the anythingCanBeEnteredHere part, which can be a collection of any number of symbols. The problem is that I can’t find any shortcut/flag that will choose any symbol So far I use this regex var regex […]

Create a Javascript RegExp to find opening tags in HTML/php template

I’m trying to write a Javascript HTML/php parser which would extract all opening tags from a HTML/php source and return the type of tag and attributes with their values while at the same time monitoring whether the values/attributes should be evaluated from static text or php variables. The problem is when I try to compose […]

Why does the string disappear when I try to test it against a regex?

What I’m trying to do is find all matches in a string, then wrap them in a styled span tag. The solution I’ve come up with uses recursion, here’s the code: function foo(node, pattern) { // alert(node.nodeValue); // alert(node.nodeValue + ‘\n’ + pattern.test(node.nodeValue)); if (pattern.test(node.nodeValue)) { // alert(node.nodeValue); var span = document.createElement(‘span’); var text = […]

Validate mm/dd/yyyy with regEx

Its not working. I don’t know regEx, but I need use it. if ($(‘input[name=”due_date”]’).val().match(“^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$”)) { $(‘input[name=”due_date”]’).after(“<span class=’v_error’>Must fill</span>”); }