...

View Full Version : RegExp compare strings problem



Kor
11-05-2004, 01:08 PM
I would like to compare two strings, and if the first one, say x, is included and is at the begining of the second string, say y, than doSomething()

var x= 'abc'
var y='abcdef'

if ( y==x+'someotherstring'){doSomething()}

any ideeas?

jbot
11-05-2004, 01:24 PM
try this: if (/^(abc)/i.test(y)) alert("woohoo: string found!";

Kor
11-05-2004, 01:41 PM
Thanx

I know the classical

if(y.indexOf(x)==0){alert('found')}

But I would like to use RegExp more often

jbot
11-05-2004, 01:44 PM
i know the classical ... I would like to use RegExp more often

RegEx is cooler, if sometimes a lot more complicated. one thing for sure, tho, is it will never be deprecated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum