たとえば、文字列を識別したい:
a = 'KI83949 anythingHere 900.00 1 900.00'
文字列は次の 3 つの部分で構成されます。
index part is the string before the first space
- 'KI83949'
これは何でもかまいませんが、ほとんどの場合、文字 + 数字です。
string between a[0] and the first floating number
with two decimal points is the seconde part
-'anything here'
それは何でもかまいません
starting with the 2-decimal-point floating number is the last part
-'900.00 1 900.00'
することができます
'900.00' or '900.00 1 1003.00' or '900.00 100.00'
float or float+int+float or float+float
ここの数字が変わります。文字列全体の場合、数値部分は常に存在しますが、前の 2 つの部分は存在しない場合があります。上記の機能を持つ文字列を他の何千もの文字列から除外しようとしています。これを表現するためにいくつかの方法を試しましたが、それでも失敗しました。正規表現の知識が乏しく申し訳ありません。最も近いショットは次のとおりです。
'.*\s?[\d.]+(\s\d)?[\s\d.]+$'
ただし、「TS90190」または「80 thda 4318」のようなものが返されます。これに何時間も費やした後、今では私を夢中にさせています. 誰かがそれを手伝ってくれますか?