I need to match and return the string index of numbers which are contained in square brackets. Example string:
Gabrilovich and Markovitch [11, 12] propose a method to use conditional random fields [6] as a training process.....
Here I would like to extract the index of any given number like 11, 12 or 6 in the above case using regular expressions. I am trying
pattern = re.compile(r'[/11/]') # for 11
result = re.search(pattern, text, flags=0)
print result.start()
However with this I am not getting desired results. Note: I would need a solution for matching the exact number I want, not any given number within brackets.
use this regex expression (\[[,\d\s ]*)11([,\d\s ]*\]) for retrieving all the 11's in the text
have a look at the example I uploaded https://regex101.com/r/lN8mA6/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With