I need a regular expression to get a word from a text input based on a index. Here the word should be in flowe brackets.
I will try to explain by giving an example.
If my input is hh{jhh}jkhjh{jkjhh{kljk}j}adajskjj}. For any character index, if it lies in between a pair of brackets I have to fetch that word including brackets.
In the above input if index is 2 or 4 output should be {jhh}.
Try this. There’s a number of problems, of course. First, you didn’t say how you want to handle nested brackets. If you need to handle nested brackets, you’re out of luck with a simple regular expression, because you need a context-free grammar for that. Also note that the following implementation is naive in that it has linear time complexity on a word lookup (time to lookup a word is directly proportional to the number of matches found). That would only be a problem for large number of matches, however. Better implementation could use, for instance, a sorted array of matches and binary search for lookup.
To use, do: