I have a little Ajax script and I'm trying to remove some CSS elements from a DIV tag and I'm have a bit of trouble with the Regex. Right now I'm trying to remove the z-index attribute. It can look something like any of these:
What is the best way to white list a set of allowable characters using regex or replace? I understand it is safer to whitelist than to blacklist, but am not sure how to go about it.
I am writing a script that will replace the src of an image when the user hovers over it. I am using jquery and regex to accomplish this and have tested it on my local server but the src of the images on the live server is different and uses a non-relative path. Here is my code
$(document).ready(function() { $("img.imagefield").mouseover(function() { var regex = "^(http|https|ftp)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/sites/all/files/[a-zA-Z]*"; var src = $(this).attr("src").match(regex) + "_silly"; [Code]...
I have a function which validates the password if there is a number: ------------------------------------------------- function findNumeric(str_obj){ regEx = /d/; if (str_obj.match(regEx)) return true; else return false; } -------------------------------------------------- The problem arises when I put a password with a space in between e.g: 'test test1'. The fucntion returns false. I've tried 's' in the regEx but the user can put the space anywhere..
Any idea how to solve this problem as I should be able to put any alplanumeric value into the password, including space.
I have a variable named "acct". I first want to remove any "-" characters from it's value. After this I want to verify that we have only exactly 12 digits in the variable.
Unfortunately I'm pretty green as far as using RegEx.
/d{12}/.test(acct); should do the second part, but how do I do the first?
Is there a way to make one regex to replace a space with " " and a tab with " "?
Currently I'm using two regex's with string.replace( ... ).replace( ... ), but that means it has to run through the string twice. Any way to do what I want in one regex?
I am using Regular Expressions and Javascript to validate a form, specifically I want to make sure that if they try to upload a file that it has a proper name w/ certain extensions (doc,pdf, rtf). The script works on IE and Mozilla but fails on Safari on the MacOSX. Here is my code..
// ok files with proper extension var reOKFiles = /^([a-zA-Z].*|[1-9].*).(doc|DOC|pdf|PDF|rtf|RTF)$/;
//where i check for the file... if(window.document.myForm.myDocument.value != ""){ var fileStr = window.document.myForm.myDocument.value; if(!reOKFiles.test(fileStr)){ alert("Please try again, you tried to upload an invalid file type for CRITERIA 1"); window.document.myForm.myDocument.focus(); return (false);
I am looking out for a regular expression that takes the following format
textfile_20060711_113441.txt
where textfile = name of the file 2006 = year 07=month 11=day 11=hour 34=minute 41=seconds. .txt is extension
The file always comes in the same format. however we need to implement checks so that user doesnt enter invalid month/day/hour/minute etc.
I have created the following regular expression textfile_(?<Year>(?:d{4}|d{2}))(?x)(?<Month>d{1,2})(?<Day>d{1,2})_([01]?[0-9]|[2][0-3])([0-5][0-9])([0-5][0-9]).[a-zA-Z]{3}
Can anyone guide me as to how do i modify this regex to suit my requirement. This regex currently is not able to handle invalid months or days etc.
Also i do not know how to integrate this regex in my javascript. Pointers or examples will be helpful.
I see the use of Javascript replace all over the web. What are all the character sequences? (sorry I am a bit of a newbie at this).
i.value.replace(/[^d]+/g, '');
I understand that /g is global and /i is case sensitive, but what are the rest? I am asking because I am trying to write a function that takes an input and replaces everything but numbers and a . (for decimal numbers).
I don't think this is "do-able" but thought I'd better check. Say I want to replace certain names in some source code as long as they are not properties (dot properties) of objects. I could use a regular expression like:
source = source.replace(rx, function ($0, $1) {return $1? $0:map[$0]});
Dot properties like .name1 are not replaced by anything new and they need to be "skipped" over by this regular expression but other name1 identifiers need replacement with "a".
One problem with this approach is that dot properties like .name1 are replaced by themselves and this is just unnecessary work. Something like a "false" return to skip replacement would be nice but the following doesn't work.
source = source.replace(rx, function ($0, $1) {return $1? false:map[$0]});
There are other ways to get around this by using something else besides replace() but I wanted to see if it could be done with the replace() method.
Now I need to do some string replace in chatmsg.value, ie, I need to look for some piece of text in chatmsg.value, and in case they are present (there may be multiple occurences of the same), to replace them with something else. This is what I got by doing a google search: Code:
function replaceAll( str, from, to ) { var idx = str.indexOf( from );
while ( idx > -1 ) { str = str.replace( from, to ); idx = str.indexOf( from ); } return str;}
chatmsg.value = replaceAll( chatmsg.value, "string to replace", "new string" ); And I place this second function just above the previous one. But it's not working. Any help friends?
I was debugging my code looking for a loop. So in the process I added a confirm request and if the user clicked cancel I coded location.replace("Kill.html"). Problem was that the JAVASCRIPT continued to run until either it finished or I used the Task Manager to end the session. :( There3 was a small difference in browsers: Firefox put up the new screen while continuing to run the JAVASCRIPT while IE didn't put up the new screen until after the JAVASCRIPT was finished. I could tell the JAVASCRIPT was still running because the confirm messages kept popping up.
<script type="text/javascript"> var str="Welcome to Microsoft! Microsoft Microsoft"; var stringToBeFound = 'Microsoft' var ReplaceString = 'site' document.write(str.replace(stringToBeFound , ReplaceString )); </script>
My problem is im trying to use string.replace that is not case sensitive and replace every string found. I could use regular expression with it but my stringToBeFound is a dynamic variable im getting it from my database
which checks I have at least one lowercase letter, one uppercase letter and one number and the string is between 8 and 16 characters.I have adapted this from another source and it works as intended on all browsers but not IE7 or IE6 (oh microsoft why do you make my life so hard)This works fine in all other browsers (IE8 is fine) but doesnt work in IE6 or IE7
I'm writing an ECMAScript tokeniser and parser and trying to find out if I can eliminate the switching from tokenising "/" as start of regex or the division operator depending on the parser feedback - essentially, if I can make the tokeniser independent of the parser. (I have a gut feeling this needs too much special casing to be worth it). Code:
I have a bunch of text that I want to split into an array of sentences. I have the following code that works just fine on FF and Chromium, but ofc has to fail on the pile of *** that is IE [code]...
It does not produce any errors, but the resulting array often has empty strings as value instead of the sentences that should be there. how to do this in a way it also works on IE?