首先,如果 [0-9]* 将出现在 23 个字符之前,我想从字符串中取出 23 个字符,然后将 [0-9]* 作为整个单词包含在内。假设我有一个字符串:
x = I have a car with tha id 6356
I have tried with x[:23]
但它用于取前 23 个字符。这将在以下情况下失败:
x = I have a car with id [0-9]*[\s]
x1 = color id [0-9]* with [0-9]*[\s]
x2 = id [0-9]*[\s] with [0-9]*[\s] has index no:[0-9]*[\s]
x3 = id[\s] with[\s] model[\s] has index no[\s][0-9]*
output of x: I have a car with id [0
output of x1: color id [0-9]* with [0
output of x2: id [0-9]* with [0-
output of x3: id[\s] with[\s] model[\
预期输出:
x: I have a car with id [0-9]*[\s]
x1: color id [0-9]* with [0-9]*[\s]
x2: color id [0-9]* with [0-9]*[\s]
x3: id[\s] with[\s] model[\s]