Extend selection to nearest particular character

Hello,

Is it possible to extend the selection in a text to the nearest previous and next dot or slash.
For example a text like this:

.PMC.12365QR/12365QR/12365QR/12365QR/12365QR.T05
.PMC.12365QR/12365QR/12365QR.T03

the user point his mouse at the bold marked 6.
I would like the selection to be extended to the previous and next slash. resulting in: 12365QR
However if the user points his mouse somewhere at the beginning or end of a line and there is no adjacent slash found, the dot character should be used instead.

using the “onmouseup” event and the getSelection method. I am able to return the selected text. But can’t figure out, or find on the internet a solution for this.

Here is my implementation: http://jsfiddle.net/zu6wkszo/

I think that it’s worth adding a debounce feature in there, for people will forever be tempted to doubleclick instead too, resulting in an undesired impact.

1 Like

Awesome. Exactly what I was looking for.
Thaks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.