RegExp.input, RegExp.leftContext, ...

Jan 19, 2007

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.

View 3 Replies


ADVERTISEMENT

Diving Into Regexp By Porting A Perl Script Over To Js That Uses Regexp To Compress Into A Bookmarklet Capable Format?

Aug 10, 2010

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

$src =~ s{^// ?javascript.+:.+
}{};

View 3 Replies View Related

JQuery :: Validation: Custom Rule With Regexp Not Catching Initial Space In Text Input

Sep 23, 2010

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.

[Code]...

View 5 Replies View Related

RegExp

Aug 30, 2005

I need to create a dynamically pattern match
for validate a number input, first without
decimals and then with 2 or more decimals.

View 9 Replies View Related

RegExp For Date

Jul 23, 2005

i have this function to check date (not mine)

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?

View 3 Replies View Related

Regexp - Removing From URL

Dec 26, 2005

I am weak when it comes to regexp but hoped someone might know in this case.
I am trying to take a url like this :

something.lasso?blah=blah&blah2=blah2&sort=hello&blah3=blah3

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 , '');

return (current + "&" + item.name + "=" + item.value);

This function would be fired like this :

All <input type="radio" name="show" value="all"
onclick="document.location=refresh(this);">
Mine <input type="radio" name="show" value="mine"
onclick="document.location=refresh(this);">

View 13 Replies View Related

RegExp FAQENTRY

Jul 20, 2005

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.

View 5 Replies View Related

RegExp Problem

Sep 22, 2007

I have a script that checks if the value of the input is valid but I have a problem with it. This is my RegExp code:

if(obj.value.match(/!@#$\%^&*()+/g))
obj.value = "Use only legit characters";

It's supposed to check if the input value has invlaid code but it doesn't seem to work.

Also I'd like to, instead of just writing the error message, to be able to change the input value to a valid one(IE: Peo$p@le@ To People)

I think it can be done with the replace statement like this:

obj.value.replace(/!@#$\%^&*()+/g,"")

So whenever it finds that invalid char it just writes nothing instead of it.

View 4 Replies View Related

Can't Use Regexp Variable Twice

Jul 17, 2006

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:

reg = RegExp('[AF]PO', 'gi');
reg2 = RegExp('[AF]PO', 'gi');

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?

View 2 Replies View Related

Regexp / What Does This Match?

Jul 1, 2010

Can someone please let me know what this matches - i can work out some but not all code...

View 3 Replies View Related

Simple Regexp

Apr 18, 2005

im tired of working all day...
please how to delete the value with regexp...
i tried this

bla.replace('value="/.+/"', '');

it wont work...

View 5 Replies View Related

Email Regexp

Mar 10, 2006

I am trying to find an email regexp but none seem to validate the following example:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@xx....xxx.xxxxxx.xx

could I have one which also validate this sort ....

View 6 Replies View Related

Regexp Replace

Jul 13, 2007

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.

View 2 Replies View Related

RegExp To Alter An Element Name?

Jul 23, 2005

Given a string like:

<input type="button" name="b1" value="Button">

I want to locate the element's name (b1) and replace it with this very name
+ some spice.

And of course it can be any kind of loose HTML syntacs:

name="b1"
NAME="b1"
name='b1'
NAME=b1
....

So it's something like (totally wrong expression, I know):

/name=(s+|'|")(name)/$1+my_spice/i

But I did not work with regexp for a longest time, and I'm just too lazy (sorry to admit) to read manuals over again just for one case.

View 7 Replies View Related

RegExp: Backreference In ClassRange

Jul 23, 2005

Consider the following RegExp:

/[1]/


ECMA-262 says:

<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.

...

View 1 Replies View Related

Validate EMail With RegExp...

Nov 3, 2005

My understanding of regular expressions is rudimentary, at best.

I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses with hypens in them.

Can anybody please help me adjust it so it will accept addresses like dag-sunde@test-domain.net too?

Here's what got:

function validateEmail(eMail) {
return /^(w+.)*(w+)@(w+.)+([a-zA-Z]{2,4})$/.test(eMail);
}

View 12 Replies View Related

RegExp Array Problem

Dec 15, 2005

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 = /^/

if(searchterm !='')
{
var matches = 0;
for(var i=0; i<myarray.length; i++)
{
if(searchme != false)
{
if (searchterm == myarray[i])
{
write (myarray[i]);
matches++;
}

}
if(matches==10) break
}
}

Obviously this is only returning exact matches and having tried to add
the RegExp into there hasn't worked as yet.

View 7 Replies View Related

Trying To Match A Newline With A Regexp.

Aug 6, 2009

Trying to match a string containing a newline, among other things.

View 4 Replies View Related

JS - Email Regexp With ONLY One Period Possible Before @

Feb 21, 2010

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.

View 6 Replies View Related

RegExp - Just Match The Part Before The <a

Sep 22, 2011

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: ((.*<)?)

View 2 Replies View Related

Regexp And Replace Problem

Nov 6, 2005

How can I replace https://www.some-body.com/cms/ with ../ in this string ?
value highly any help

var str="<br>https://www.some-body.com/cms/file1.txt<br><br>https://www.some-body.com/cms/file2.txt<br><br>";

str=str.replace(

alert(str)

View 3 Replies View Related

RegExp Navigator.userAgent

Jan 5, 2003

Why is /MSIE (5.5)|[6789]/.test(navigator.userAgent) true
when navigator.userAgent == "Opera/7.0 (Windows 2000; U) [en]" ?

View 3 Replies View Related

RegExp Works In Firefox Not IE

Sep 13, 2010

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).

View 4 Replies View Related

Find And Replace (regexp)

Feb 27, 2010

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.

[Code]....

View 5 Replies View Related

RegExp: How To Match On Exact String Only?

Jul 23, 2005

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.

View 6 Replies View Related

RegExp - Build Dynamic Pattern

Jul 23, 2005

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?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved