views:

40

answers:

2

Hi,

with $("#TextInputElement").select()

I am able to select a text (mark it) in an in an input text field.

Now I only want to select the text in between brackets in that input field. I have the regular expression match(/-[^-]*-/) to select, but how would I apply this to only select the text inside the input field between brackets?

[noselect]textToBeSelected[/noselect]

thx

+4  A: 

You need to use createTextRange/setSelectionRange

Example showing how to use them in a cross browser manner

epascarello
A: 

Try this code:

var text = $("#TextInputElement").select();
var pattern = /\[(.*)\]/g;
text = text.match(pattern);
pMan