PDA

View Full Version : Need help with regexp matching only in sequence



sfraise
Feb 14th, 2011, 10:23 PM
I have an autocomplete script but it's currently returning results in a character is in the name anywhere at all, what I need it to do is only return matches if the characters are in sequence only.

Example of how it is now if you type S it will return:
Science
Host
Pass

What I need it to do is only return a match if the first character is an S, and so on down the line in order.

So if you type sam it should only return matches where the first 3 letter are sam in the order it's typed.

Here's how the regexp is now:
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");

Philip M
Feb 14th, 2011, 10:37 PM
When posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.

It should be obvious why this is required.