1
votes

I have a string that looks like this:

17/07/2013   TEXTT TEXR          1  Text                                 1234567            456.78     987654

I need to separate this so I only end up with 2 values (in this example it's 1234567 and 456.78). The rest is unneeded.

I tried using string split with %A_Space% but as the whole middle area between values is filled with spaces, it doesn't really work.

Anyone got an idea?

2
Is your list consistent in this fashion? That is, will you ever have any words with spaces? Will the TEXTT TEXR ever change?bgmCoder
the 2nd value (i.e. TEXTT TEXR) can be anything from 1 to 4 words. The next value is always 1 and the following value is always "Text". The values after that are always different, but always similar.user2593572

2 Answers

1
votes
src:="17/07/2013   TEXTT TEXR          1  Text                                "
. " 1234567            456.78     987654", pattern:="([\d\.]+)\s+([\d\.]+)"
RegexMatch(src, pattern, match)
MsgBox, 262144, % "result", % match1 "`n"match2
0
votes

You should look at RegExMatch() and RegexReplace().

So, you will need to build a regex needle (I'm not an expert regexer, but this will work)

First, remove all of the string up to the end of "1 Text" since "1 Text" as you say, is constant. That will leave you with the three number values.

Something like this should find just the numbers you want:

needle:= "iO)1\s+Text"
partialstring := RegexMatch(completestring, needle, results)

lenOfFrontToRemove := results.pos() + results.len()
lastthreenumbers := substr(completestring, lenOfFrontToRemove, strlen(completestring) )
lastthreenumbers := trim(lastthreenumbers)
msgbox % lastthreenumbers

To explain the regex needle: - the i means case insensitive - the O stands for options - it lets us use results.pos and results.len - the \s means to look for whitespace; the + means to look for more than one if present.

Now you have just the last three numbers.

1234567            456.78     987654

But you get the idea, right? You should able to parse it from here.

Some hints: in a regex needle, use \d to find any digit, and the + to make it look for more than one in a row. If you want to find the period, use \.