Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Why does the string not match the regular expression?
Pattern: ^.*\[[^\d,]*\].*$
String: anything[2287172,1932347]anything
You need to leave only the contents of the [] brackets, but the string does not change according to this pattern. Why?
Answer the question
In order to leave comments, you need to log in
Because it needs to be:
import re
string = 'anything[2287172,1932347]anything'
pattern = re.compile('^.+\[([\d,]+)\].+$')
string = pattern.match(string).group(1)
print string
^.+\[([\d,]+)\].+$
If you need to split the numbers, then through split
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question