I have a string: "fdfdfd.dfdfd.dfdfdf.dfdfdf"
. I want to get the location of the last dot. I tried this:
Index = re.search(r"\w + '.' \w+$", string)
but it doesn't work. How can I do this?
尝试string.rfind()
: http : string.rfind()
例如
"fdfdfd.dfdfd.dfdfdf.dfdfdf".rfind('.')
I could be wrong, but I suspect that what you really want is the tail end of the string (whatever comes after the dot). If so, you can do this:
tail = re.search(r"\.(\w+)$", string).group(1)
Also see @bradley.ayers comment for a simpler answer. I hadn't heard about rpartition
till now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.