In Windows, when you perform double-click in a text, the word around your cursor in the text will be selected.
(This feature has more complicated properties, but they will not be required to be implemented for this challenge.)
For example, let
| be your cursor in
abc de|f ghi.
Then, when you double click, the substring
def will be selected.
You will be given two inputs: a string and an integer.
Your task is to return the word-substring of the string around the index specified by the integer.
Your cursor can be right before or right after the character in the string at the index specified.
If you use right before, please specify in your answer.
The index is guaranteed to be inside a word, so no edge cases like
abc |def ghi or
abc def| ghi.
The string will only contain printable ASCII characters (from U+0020 to U+007E).
The word "word" is defined by the regex
\w is defined by
[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_], or "alphanumeric characters in ASCII including underscore".
The index can be 1-indexed or 0-indexed.
If you use 0-indexed, please specify it in your answer.
The testcases are 1-indexed, and the cursor is right after the index specified.
The cursor position is for demonstration purpose only, which will not be required to be outputted.
string index output cursor position abc def 2 abc ab|c def abc def 5 def abc d|ef abc abc 2 abc ab|c abc ab cd ef 4 cd ab c|d ef ab cd 6 cd ab c|d ab!cd 1 ab a|b!cd