Making A Smart Regex

Dec 14, 2005

I am trying to write a regex that will parse BBcode into HTML using
JavaScript. Everything was going smoothly using the string class
replace() operator with regex's until I got to the list tag.
Implementing the list tag itself was fairly easy. What was not was
trying to handle the list items. For some reason, in BBcode, they
didn't bother defining an end tag for a list item. I guess that they
designed it with bad old HTML 3.2 in mind where you could make a list
by using:

<ul>
<li>item 1
<li>item2
</ul>

However, I need to make this XHTML compliant, so I needed to add the
</li> tag into the mix. Unfortunately, the only way to find where to
put it is to find the next[*] (<li>) tag or an open list (in the case
of nested lists) or close list tag. I was trying to get a rule that
handles the list items to work, but it only matches the first item in
any list. Here is the line of code:

bbcode =
bbcode.replace(/[list(=1|=a|)](.*?)[*](.*?)([*]|[list]|[/list])/g,
'[list$1]$2<li>$3</li>$4');

First, I check to make sure that the list item is inside a list. Then,
I match the[*] tag to find the start of the item, then I match either
the next[*],, orto determine the end of the item.
This successfully prevents a list item outside of a list from being
made into a <li> element, but only matches the first list item in a
list. Is there any way to make this match all occurances of this
pattern without looping over the statement until the pattern can no
longer be found?

View 13 Replies


ADVERTISEMENT

JQuery :: Making Password Field Regex Valid

May 28, 2009

I'm trying to make my password field regex-valid, but don't know what to add.
Here is my code :
$.validator.addMethod("integer", function(value, element) {
return !jQuery.validator.methods.required(value, element) || /^d+$/
i.test(value);
}, "Numbers only please");
$("#register_form").validate({
rules: {
user_password: {
minlength: 6,
integer:true
},}});
But this does not work.

View 3 Replies View Related

Smart Substring

Sep 9, 2007

If I have the following variable which contains the drop down menu for list of card numebrs:

var abc='<option value="1234567890123456">1234567890123456</option><option value="0987654321987654">0987654321987654</option><option value="0147852369014785">0147852369014785</option>'

How can I pass this variable to a function and mask only the dispalyed card number? i.e. to have the following result:

<option value="1234567890123456">1234XXXXXXXX3456</option><option value="0987654321987654">0987XXXXXXXX7654</option><option value="0147852369014785">0147XXXXXXXX4785</option>

Note: the number of options in the drop down menu may varry, in this example its only 3 options, it might be more or less, this is why I called it "Smart Substring".

View 1 Replies View Related

Building 'smart' Forms With DOM 2

Mar 14, 2003

I'm fooling around with building a form that grows depending on the users input (relatively new to DOM 2 - but fun stuff!) I'm working on getting it to work (rather than being pretty - there are many improvements that could be made).

My question is has anyone seen any similar examples out there? The more I build on this thing, the more I believe there has to be another way... (like rather than creating every pull-down box - yes, I should put that into it's own function! - should I be playing with visibility and positioning?) Code:

View 1 Replies View Related

JScript Smart Table

May 4, 2006

I have an application where I have 9 items to choose from and desire a table that will allow only 3 items (any 3 items) to be chosen then check out of the table.Check out can not be allowed unless only 3 items are selected.

Is the JScript applications somewhere that will perform this logic?

View 2 Replies View Related

Smart AJAX Autosave?

Dec 5, 2006

I have an autosave feature that, well... autosaves every minute. Now I could very well become the biggest abuser of my own feature. I currently have 8 windows open - I tend to just leave windows open for a long time. As a result, the javascript would be running every minute saving, creating unnecessary load on the server.

How could I make the autosave smart and only save if they are actively "working" with it? The only thing I can really think of is to have like a variable that sets to true whenever something happens, set to false whenever it saves, and only save when the var is true. Problem is, I have a lot of functions for events that I would need to attach it to... I'm sure I would miss it somewhere.

View 3 Replies View Related

Replace Smart Quotes And Not HTML?

Jun 2, 2009

I'm using this rich text editor. Whenever a user pastes rich text from a program like Microsoft Word, the program's smart quotes are not understood by the browser (they appear as a diamond with a question mark in it). I ran a php function on the post value to replace all quotes with ascii characters, but realized that it also replaces the quotes present in the html generated by the javascript.Is there a way to convert smart quotes to normal quotes without also tampering with the html content?

View 1 Replies View Related

Smart Card Reader - Make It Run In All Browsers?

Sep 8, 2010

How can I write javascript codes to interact with a smart card reader? I have found some activex controls and examples, but I think, it will be limited to IE only.How can I make it run in all browsers, if the card reader driver is installed, and the hardware is available for use?My problem is to make sure that the user puts his/her own smart card in the reader unit before he signs up in a website (a particular website, that I will be coding for).

View 1 Replies View Related

Smart Search Form & Browsers Saved Search Fields?

Aug 18, 2010

I have created a similar smart search like yellowpages:[URL]... Here is the problem I have with mine:

Lets say I search 'Attorneys' I start typing 'Att' ... then 'Attorneys' shows up in the smart search so I click on it and press enter. The next time I start typing 'Att' my browsers saved search field pops up over the websites smart search. Here is an image which might help explain the problem a bit more:

View 1 Replies View Related

Smart "Top Of Page" Script?

Sep 29, 2004

I found this code online. It detects if vertical scrollbars are present in your browser, and if so, it adds a link to the top of the page at the bottom of the open page.

The only thing is, it prints the link in the bottom left corner of the screen, and I really need it to show up in a specific area. Does anyone know of a similar script I can use for that? I want one that will only show up if the page has vertical scrollbars. Code:

View 21 Replies View Related

RegEx In Javascript

Jul 23, 2005

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.

View 6 Replies View Related

RegEx In Javascript?

Jul 23, 2005

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?

View 4 Replies View Related

Issues Getting And Regex'ing A Url

Jan 9, 2006

Basically i want to get the current url, and then replace http:// with
something else.

Here is the current code.

var current_url = window.document.location;
var re = new RegExp("http://", "g");
if(re.test(current_url)) {

me = current_url.replace(re,"http://www.addme.com/");

window.alert("found :: " + me + " :: " + current_url);
} else {
window.alert("not");}

if my page was http://ww.google.com 'd get the alert to be:

found :: undefined :: http://www.google.com.

I dont understand why i am getting undefined. When re.test() works.
surely that means the regex is correct.

View 14 Replies View Related

RegEx Question

Jun 15, 2006

Trying to match the entire following object literal code using a RegEx.
var Punctuators = { '{' : 'LeftCurly', '}' : 'RightCurly' }

Variations on the idea of using /var.*{.*}/ of course stops at the
first }.

View 7 Replies View Related

Space In REGEX In IE6

May 9, 2007

I was using the following code:

element.value = element.value.replace(/ /g,'');

to remove all the spaces in a string.

However in IE6 it complained with and "Expected ')'" error.

How can I tell IE6 to replace just spaces (i.e. not using s)?

I tried / / and /[ ]/ but neither of them worked either.

View 13 Replies View Related

Regex Help Needed

May 18, 2007

I need to strip everything from a file except what is between <body>
and </body>

View 2 Replies View Related

Regex Not Working In IE7 And 6?

Oct 13, 2009

ok heres a regex

/^(?=.*d)(?=.*[A-Z])(?=.*[a-z]).{8,16}$/

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

View 1 Replies View Related

Divisions And Regex

Oct 23, 2005

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:

View 2 Replies View Related

Regex For A-z With A Comma?

Jun 27, 2010

I have been playing with this regex for a few hours now I want to make it so it accepts commas also.

At the moment it works with A-z and - . ' but can't seem to figure out how to include commas.

View 4 Replies View Related

Regex Fails In IE

Jun 21, 2011

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?

View 1 Replies View Related

Conditional Regex

Oct 27, 2004

i have the following regex:

(s*{s*(<?)s*(>?)s*}s*)

this needs to be able to match a string and make the following replacements:
if the string matches without < or >, replace the match with a space, a replacement string, and another space. if < matches also, do not add the left space. if > matches, do not add the right space. if < and > match, do not add the beginning or ending space

Old {} String => Old Replacement String
Old {<} String => OldReplacement String
Old {>} String => Old ReplacementString
Old {<>} String => OldReplacementString

this will have to be done a LOT of times, so efficiency is very important the answer in php is below. can anyone help me figure out how to do it in javascript? PHP Code:

View 4 Replies View Related

Javascript Regex

Dec 21, 2004

In have a string of data like so:

<div id="feedback">
<p>[DEC 12th Anthony]I like it[DEC 12th Anthony]I agree</p>
</div>

I'm trying to use regex to add a <br /> before each item in hard brackets so the comments are broken out. Here's what I've tried.

re = /(.*])/gi;
vTemp = aSourceObject.innerHTML.replace(re,"<br />$1");

What I end up getting is:

<div id="feedback">
<p><br />[DEC 12th Anthony]I like it[DEC 12th Anthony]I agree</p>
</div>

It gets it right, but only for the first item, not the second one. If I tell it to put the <br /> after then I get

<p>[DEC 12th Anthony]I like it[DEC 12th Anthony]<br />I agree</p>

So its like its reading the entire section in brackets as one match instead of 2 seperate matches..

View 2 Replies View Related

RegEx With Javascript

Nov 15, 2006

I need information about javascript & regular expression.please suugest me any book or tutorial web site.

View 2 Replies View Related

RegEx That Allows Whitespace?

Jul 21, 2010

How would I get this variable to allow whitespace?

var illegalChars = /W/; // allow letters, numbers, and underscores

View 11 Replies View Related

Regex: Remove A Specified Parameter From URL

Jul 23, 2005

I need to write a function that will remove a specified parameter from a
URL. For example:

removeParam("param1", "http://mysite.com/mypage.htm?param1=1&param2=2");

would return:

"http://mysite.com/mypage.htm?param2=2"

I'm thinking that string.replace(/regex/, ""); would do the trick, but how
do I construct a correct regex?

I see a problem if the parameter name ("param1") happens to contain any
characters that have a special meaning in a regular expression.

View 3 Replies View Related

Split Or Regex Difference Between FF And IE

Jul 23, 2005

I don't know where the actual issue is, but hopefully someone can explain.

The following displays "5" in FireFox, but "3" in IE:

<script type="text/javascript" language="javascript">
var newString = ",a,b,c,";
var treeArray = newString.split(/,/i);
alert(treeArray.length);

</script>

View 1 Replies View Related







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