I found this in felgall's page. I added script tag
<script type="text/javascript">
var re = /(t)he/g;
var mystring = "Over the moon.";
re.text(mystring);
alert(RegExp.input); // or RegExp.$_
alert(RegExp.leftContext); // or RegExp["$`"]
alert(RegExp.rightContext); // or RegExp["$'"]
alert(RegExp.lastMatch); // or RegExp["$&"]
alert(RegExp.lastParen); // or RegExp["$+"]
alert(re.source);
</script>
I don't see message box. Please tell me what I can do.
I'm finally diving into regexp by porting a perl script over to js that uses regexp to compress javascript into a bookmarklet capable format.I've successfully worked out 90% of the expressions but am troubled with a few, this one at the moment is odd:I want to remove the first line if it hasjavascript:So I thought str.replace(/^javascripts+:s+/, "") would be ok. I want javascript text, any space, colon, any space and new line. what I'm doing wrong.btw this is the original perl version
So I created a custom rule following numerous examples out on the web for a dynamic text input, but for some reason it seems to be letting spaces through even though my regexp tests out ok to not match when the value is any combination of spaces...
$.validator.addMethod("noSpace", function(value, element){ return this.optional(element) || /^[a-z0-9][a-z0-9_ ]{0,70}$/i.test(value); }, "Please enter a name starting with either a letter or a digit."); $('#form').validate({ rules: { [Code]...
The odd thing is, it will work if you type in a space followed by a character, but if you type in one space, or one space followed by x number of spaces, it just lets it through like it's valid. But yet when I look at the demos and examples that I pulled this from, they never let those scenarios go through.
function (s_date) { // check format if (!re_dt.test(s_date)) return false; // check allowed ranges if (RegExp.$1 > 31 || RegExp.$2 > 12) return false; // check number of day in month var dt_test = new Date(RegExp.$3, Number(RegExp.$2-1), RegExp.$1); if (dt_test.getMonth() != Number(RegExp.$2-1)) return false; return true;}
it will check in this format DD-MM-YYYY is it possible to modify it to be (MM/DD/YYYY OR DD/MM/YYYY) in one function?
And remove the &sort=XXX without hurting the rest of the url. The parameter to be replaced would be a parameter passed to a function. Here is what I have so far:
function refresh(item) { current = document.location.href; if(current.match(item.name+'=')) //pseudo code here //current.replace(item.name regexp , '');
An important question, probably not treated by many otherwise worthwhile sources, must be on feature detection of the newer RegExp facilities - for example, greedy/non-greedy.
The answer may be that it is not possible to do so in a safe manner; that one can do no better than something like
document.write("Testing non-greedy :- ") X = /<trialRegExp>/.test(string) document.write("survived.")
That is, nevertheless, a useful answer; if it is right, it prevents the naive seeking anything better, and if it is wrong someone will soon say so.
Where a page requires an advanced RegExp facility, it is best to have a controlled failure at a well-chosen point.
Putting something in the posted FAQ will provide an opportunity for adding a reference to the Notes; and, without such a reference, their value is much reduced.
I have found that I can't use a regexp variable twice. For instance, if I have the following code then the first will evaluate true and the second one false, despite the fact that they should both evaluate true:
reg = RegExp('[AF]PO', 'gi');
if (reg.test(document.getElementById('address_line_1').value) && reg.test(document.getElementById('address_line_2').value)) alert('You entered an APO or FPO address!');
To get the code above to work I have to do the following:
if (reg.test(document.getElementById('address_line_1').value) && reg2.test(document.getElementById('address_line_2').value)) alert('You entered an APO or FPO address!');
Why is it I have to have two regexp variables created? Is the variable "one use" or am I doing something wrong here?
I want to replace a string after checking it is valid by passing the values to a function.
The string is '<img width="300" height="300">'
Code: var text = '<img width=300 height=300>' text = text.replace(/<img width=(.*?) height=(.*?)>/gi, check_img($1, $2)); The $1 and $2 values are not being passed to the function. This same method works in PHP by the e Modifier but not in JS.
<quote (with slight modification of non-ASCII character)>
15.10.2.11 DecimalEscape
The production DecimalEscape :: DecimalIntegerLiteral [lookahead != DecimalDigit] evaluates as follows.
1. Let i be the MV of DecimalIntegerLiteral. 2. If i is zero, return the EscapeValue consisting of a <NUL> character (Unicode value 0000). 3. Return the EscapeValue consisting of the integer i.
I'm trying to write a RegExp that will return search an array and return the closest 10 matches, for example, if i entered "Hel" and my array contained "Hello", "Hell", it would return Hello and Hell, however, if i entered "ell" it wouldn't return anything.
The code that i need to modify is: -
var searchterm = "Hel"; var re = new RegExp("^") re = /^/
I am attempting to do a basic email format validation in JavaScript on a very basic form with fields for name, address, email, etc.
Requirements: A period can occur before the @, but not twice in a row -- as in jane.doe@xyz.com but not jane..doe@xyz.com. Email must start with a letter. I'm also allowing underscores and hyphens before the @, but I'm not worrying about whether there's only one of each -- I'm just allowing those. Must end in .com, .net, .org. Nothing else.
[Code]...
I have read extensively on this site and several others and haven't found a solution to the "one and only one period allowed in succession, but not required" problem. I haven't found a successful way to limit periods to only 1 in a row yet still have the rest of the validation work properly. I get the symbols in general, but as a newbie can't seem to make them do this one thing that I want them to do.
I have this string: this is my test <a href="yay.html">yay</a> and want to just match the part before the <a...: this is my test I can't figure out the regular expression for this. I've tried everything I can think of. It seems that it needs to do a non-greedy search on the first < it finds, but nothing works, like: ((.*<)?)
I have a javascript function on my page named "print", that opens up a new window and a print dialog so the user can select a printer and print the page. The html itself is in a frame, so the print function extracts the innerHTML and then presents it to the user in the new window. After extracting the innerHTML, I'm attempting to remove any links to avoid having the user click on them (I just want the user to print). This works fine in FF (3.6.9), but causes IE (IE7 and 8) to lock up in a rather nasty manner. The "destination" in this case is simply the current page (e.g., index.aspx).
If I find a line like this: Code: |Note|Dur:16th,Grace|Pos:n-10^|Opts:Stem=Up , I will have to insert the first character after Pos: (n, b, or #) into the Pos: field of a later "Chord" line (will be a list separated by commas). If there is a number (positive or negative) following Pos:, nothing needs to be done.
I am trying to figure out how to set up my reg exp search so that the search will only match on the exact word.
Here is the current problem code:
Word1 = "RealPlayer.exe" Word2 = "Player.exe"
RegExp re = Word2; if (re.Find(Word1)) { bFound = TRUE; }
Currently the bFound is set to TRUE since "Player.exe" is found within "RealPlayer.exe". But I only want bFound to be TRUE is if the entire word matches.
I have written an ASP.net app that pulls settings from a database. Part of the setting definition is a regular expression that I want to use on the client via JavaScript for data validation...
1) Sample code for the setting object: ---------------------------------------------------- function setting(id, name, validationPattern, validationMsg) { this.id = id; this.name = name; this.validationPattern = validationPattern; this.validationMsg = validationMsg; }
2) Sample code on the page that creates a new setting object: ---------------------------------------------------- setting(1, 'test', '^d{1,1}$|^d{2,2}$|^100$', 'invalid value');
3) The issue: ---------------------------------------------------- The setting object gets built just fine except the pattern argument gets escaped by javascript!!!
^d{1,1}$|^d{2,2}$|^100$
GETS ESCAPED TO
^d{1,1}$|^d{2,2}$|^100$ (Notice how the double is now a single )
Is there any way for me to preserve the pattern text as is?