Finding Position Of A RegExp Subexpression
Apr 21, 2006
I need to come up with a function
function regExpPos (text, re, parenNum) { ... }
that will return the position within text of RegExp.$parenNum if there
is a match, and -1 otherwise.
For example:
var re = /some(thing|or other)?.*(n(est)(?:ed)?.*(parens) )/
var text = "There were some nesting parens in the test";
alert (regExpPos (text, re, 3));
should show 17
Would anyone have one of these?
View 7 Replies
ADVERTISEMENT
Aug 13, 2005
How can I check if a number exists by itself in this string by using
the RegExp object?
var mystring = "11,111,01,011";
var match = "1";
var re = new RegExp( match );
var isFound = re.test( mystring ) );
Running this code returns 'true' which is not what I want since number
one doesn't exist by itself. I need to use the "match" variable since
it will change depending on user input.
I can only get it to work without variables in the expression. E.g.
var re = new RegExp( /1/ );
View 6 Replies
View Related
Jul 23, 2005
I would like to use one or more RegExps to validate country names as having
the first and last words beginning with an uppercase letter, intermediate
words beginning with either uppercase or lowercase, and all other characters
being lowercase characters. For example:
Turks and Caicos
The difficult part is that I want to obtain save the string positions of the
invalid characters in an array, rather than just obtain a true or false
value.
Can anybody with more experience with Regular Expressions than me suggest
some code, sites, or approaches.
View 5 Replies
View Related
Sep 28, 2005
How can I get the position of an element such as a div?
View 2 Replies
View Related
Sep 8, 2010
I've been trying the find the (x,y) co-ordinates of an element. I've been using;
document.getElementById(element).style.top
document.getElementById(element).style.left
However this doesn't always work in my script. Now, I've googled how to find the position of an element. And come accross many scripts which supposedly all find the position of any object. Some are very long scripts and some are very short all using a variety of methods. Incidently none of which work, they all return (0,0).
View 3 Replies
View Related
Aug 31, 2005
I am trying to dynamically find the position of an anchor on the page. I have a page where you can get to the anchor in the normal way (http://www.mypage.com/index.html#anchorname), but there is a script on that page that adds fields dynamically. This causes IE to lose the place where it was supposed to scroll to (via the anchor).
After the fields are added, I want to rescroll to the location of the anchor. Here is the code that I have running on the page. Code:
View 2 Replies
View Related
Sep 30, 2005
I got a script from brothercake which gets the absolute position for an element. Its pretty neat - recursively adding up offsets. I got it from the image transition scripts on his site.
However, this script uses offsetTop, offsetLeft and offsetParent, which dont seem to be supported by FireFox (or maybe I'm doing something wrong).
Here's brothercake's script:
getRealPosition = function()
{
this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
this.tmp = arguments[0].offsetParent;
while(this.tmp != null)
{
this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
this.tmp = this.tmp.offsetParent;
}
return this.pos;
}
It seems to work for Opera and IE - but not FF. Cant say for other browsers. I've come to rely on it for a part of my 'cross-browser' page. Any thoughts on what I can do?
What I can't figure out is why it seems to work fine on brothercake's site - even in FireFox. I'm supposing that the positioning script must be working because the images appear in the right spot.
View 4 Replies
View Related
Sep 7, 2010
I have generated menus from an XML file. The XML also defines sub menus that are to open when the mouse is over any one of the menus.The menus are div tags with text in them. The location of each is based on the order that they added in and the width of the text with some padding.When the users mouse moves over the menu item it should pop up a sub menu at a relative position to the menu item.How do I get that position and width of the menu the user is over if it has never been set explicitly? Is there a way or not? If not what is the best solution for something like this?
View 1 Replies
View Related
Sep 8, 2010
I've been trying the find the (x,y) co-ordinates of an element. I've been using;
Code:
document.getElementById(element).style.top
document.getElementById(element).style.left
However this doesn't always work in my script. Now, I've googled how to find the position of an element. And come accross many scripts which supposedly all find the position of any object. Some are very long scripts and some are very short all using a variety of methods. Incidently none of which work, they all return (0,0). I have a question, why would someone create a script to do what one line of code can do? Am I missing something.
View 3 Replies
View Related
Oct 5, 2006
Is there a possibility to find out the coordinates, relative to the whole
screen, or at least relative to the browsewindow, where an element ( e.g. link or
picture ) begins or ends?
View 2 Replies
View Related
Oct 30, 2002
Is it possible to do this? Say I want to find out where on the screen a specific div is, and i want to know the values of the left and top properties. Can i find this out? If so, how?
View 14 Replies
View Related
Sep 3, 2010
I am hoping you can help me. I am finding this problem rather complex to solve. I need to be able to find the surrounding text at the mouse position. For example, if a user clicks on a word in a paragraph, I need to programmatically know what the text is surrounding the click point. The text in question is not just content text, but DOM elements read in as text rather than the DOM element itself. For example, if a user clicks at the word "This" in the following:
<table><tr><td>This is good</td></tr> then I would like to know how to get the text "<td>" just before the "This" as text, not as a DOM element. Furthermore, how can I "enlargen" the scope of my capture, such that I can programmatically get the "<table><tr><td>" part as well as the "is good</td></tr>" part?
View 3 Replies
View Related
Feb 16, 2006
Question 1
----------------
I am writing an advanced BBCode system for my forums and I would like
to be able to find where the cursor was positioned last in the text so
I could insert the BBCode there.
Question 2
----------------
Again I am writing an advanced BBCode system for my forums and I would
like to make is so that when someone puts in a [b] tag it goes bold, so
kind of a WYSIWYG editor and also for other things like [img] tags and
[url] tags. So could someone tell me how to do that. I would preferably
like it to still use the textarea tag, or at least a form component so
my existing code works.
View 2 Replies
View Related
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
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
View Related
Nov 23, 2011
i,m trying to make a map who show me as position A and a target adress as point B.I have made it so i can choose adress a and adress b from a dropdown but i want to automaticly load my position as possition A then choose position B from a dropdownlist. How can i do this ?
[Code]....
View 2 Replies
View Related
May 13, 2010
I'm new to javascript and am not sure why this works in firefox and not chrome. I am trying to create a script that keeps an object fixed horizontally while bing positioned absolute vertically. if I replace the toPP variable in document.getElementById('fire').style.top = toPP; with say '50px' it will move the element down 50 pxs, but how I have it currently it doesn't do anything in chrome
<script type="text/javascript" >
window.onscroll = function()
{
if( window.XMLHttpRequest ) {
var x = 0 -document.documentElement.scrollTop;
var toP = String(x);
var toPP = toP + "px";
[Code]...
View 7 Replies
View Related
Aug 11, 2009
#navigation li is the parent element, which is positioned relative.The ul element above that is also position relative. I previously tested a click function and was able to confirm I was getting the correct position back, so now I just need to set the CSS property correctly for all of those links.The reason I want to do this is I have a set of links that appear over a photo of a city skyline. When you hover over those items, I want them to be given a background image that is a blurred and lightened version of the same photo so it needs to line up (sort of like the tabs are made of frosted glass).
View 1 Replies
View Related
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
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
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
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
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
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
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
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