Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expressions.....Anyone know a good site that describes usage 1

Status
Not open for further replies.

mit99mh

Programmer
Sep 24, 2002
246
GB
I've started using regular expression recently but they are still something of a black art - does anyone know of a good site that explains the basics?

Any help much appreciated.
 
4GuysFromRolla has some decent articles on the subject from an ASP point of view, the Java Forum here has a rather long FAQ on the subject that a friend of mine wrote, he even went back and used pretty colors :p

-Tarwn
 
Regular Expression question
Hello Folks,
I have a regular expression question. I want to make sure a field is at least 6 chacaters and has both numbers and letters in it. It has to have at least one of each - Do I have to walk through each character and check it or can I set up a quick regular expression? Thanks for your help.

- Mark
 
mark-

I believe your post would be better served if it were posted by itslef, rather than inside another....nevertheless, as this does pertain to both questions, check this out:

"Why is it always the quiet ones?"

Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
AIM & MSN: robacarp
 
mhamilton3-


<script type = &quot;text/javascript&quot;>

var str = &quot;123abc&quot;;

var A = /[a-zA-Z]/;
var B = /[0-9]/;

function X(){

if(str.match(A) && str.match(B) && str.length == 6)
{
window.alert(&quot;Letters + Numbers checks out&quot;);
}

}

</script>
 
thread216-510460

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811

onpnt2.gif
 
Noticing your use of the Match method of the String object in the example in the last post, I'm wondering if you can offer a suggestion about why the following code is not working.
Code:
		window.alert ( 'purl = ' + purl ) ;
		ourl = new String ( purl ) ;						// Create string object for testing.
		if ( ourl instanceof String ) {
			window.alert ( 'Variable ourl is a String object.' ) ;
		} else {
			window.alert ( 'Variable ourl is not a String object.' ) ;
		}
		if ( ourl.search ( /^http/i ) == -1 ) {				// Is URL fully qalified.
			urlisfq = 0 ;									// No.
			window.alert ( 'URL is local.' ) ;
		} else {
			urlisfq = 1 ;									// Yes.
			window.alert ( 'URL is fully qualifed.' ) ;
		}
		a = urlisfq ;										// Set default; no address text box if local URL, else show location bar.
		orx = new RegExp ( '/(\..*?$)/' ) ;
		orx.compile ;
		if ( orx.exec ( ourl ) == -1 ) {					// Does URL have an extension?
			window. alert ( &quot;There is no extension.&quot; ) ;
			urlext = '' ;
		} else {
			window. alert ( &quot;There is an extension.&quot; ) ;
		 	urlext = RegExp.$1 ;
		}

Running in Internet Explorer 6 SP1, if I feed set variable url to index.html, I expect [$1] to be equal to .html. Instead, it returns blank.

 
TXWizard,

don't include the regex delimiters &quot;/&quot; when using new RegExp...change to:

orx = new RegExp ( '(\..*?$)' ) ;


also, to see if exec() failed, use:
if ( !orx.exec ( ourl ) ) {
instead of
if ( orx.exec ( ourl ) == -1 ) {

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top