1

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? Commented Jul 18, 2013 at 3:01
  • 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. Commented Jul 18, 2013 at 3:13

2 Answers 2

1
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
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, you got the regex - I tried but couldn't quite figure it out.
0

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 \.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.