0

There is a problem in java script regular expression .I want my regular expression should be dynamic and it match the string with starting characters.This issue happens in auto complete

Example:

var myString = "tester Developer" ;

variable = values which typed in input fields;

var regExp = ('^' + variable + '$');

This regExp is change when user type a character.. if user types ' t' (or) 'te' (or) 'tes' ... it returns true. if 'td','ht','fd'(which is not a starting letter of myString) it returns false..

1

1 Answer 1

1

I think what you are looking for is this:

var re = new RegExp("ab+c");

See this for a more detailed explanation: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions

Sign up to request clarification or add additional context in comments.

4 Comments

how do i check it with my string
var re = new RegExp("^" + variable + "$");
It matches only both string are same. but what i want is str1=" tester" str2 ="tes" or str2="te" like this..the match fun returns true for str1 and for given str2's matches... its for auto complete process
oh. your question is about regular expressions. Not javascript. var re = new RegExp('^' + variable + '.*$'); i believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.