AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Regex with multiple lines question [SOLVED]

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
rockit0



Joined: 06 Oct 2006
Posts: 22

PostPosted: Wed Mar 26, 2008 11:12 pm    Post subject: Regex with multiple lines question [SOLVED] Reply with quote

This is my var:

Date,Open,High,Low,Adj Close,Volume
2008-03-20,23.03,23.65,22.92,23.00,3155500
2008-03-19,24.94,25.16,23.70,23.70,1788600
2008-03-18,24.42,25.30,24.03,24.90,1893100
2008-03-14,26.85,26.93,24.60,25.46,1751900
2008-03-13,26.55,26.92,26.00,26.30,1620600
2008-03-12,27.50,27.75,26.51,27.19,2040400
2008-03-11,26.60,27.38,26.31,27.35,2645600
...

Every line has 6 information separated by ,
the NeedleRegEx looks like (.*),(.*),(.*),(.*),(.*),(.*) for each line

How can i set up my var to looks like:
$1,$2,$3,$5,$4

ex:
2008-03-11,26.60,27.38,26.31,27.35,2645600
will be:
2008-03-11,26.60,27.38,27.35,26.31

Thank's for help


Last edited by rockit0 on Mon Mar 31, 2008 2:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
evan
Guest





PostPosted: Thu Mar 27, 2008 12:55 am    Post subject: Reply with quote

read whole line as a variable
then string split the , as:
var1=2008-03-11,
var2=26.60,
var3=27.38,
var4=26.31,
var5=27.35,
var6=2645600
replace the , to space
the append the line as %var1%,....%var5%,%var4%
loop another line...continue...
Back to top
Tuncay



Joined: 07 Nov 2006
Posts: 383
Location: Berlin

PostPosted: Thu Mar 27, 2008 9:21 pm    Post subject: Reply with quote

@evan
Loops and StringSplits are good practice and a some easier understand from many beginners. But calling it with one RegExReplace function is drastically faster. But regular expressions are often a bit tricky.

@rockit0
Here is my solution:

If I have understand it correctly, you want to ...:
  1. ... Cut out the sixth element of every line
  2. ... and swap element 5 with every element 4 of every line.

Script:
Code:
var =
(
Date,Open,High,Low,Adj Close,Volume
2008-03-20,23.03,23.65,22.92,23.00,3155500
2008-03-19,24.94,25.16,23.70,23.70,1788600
2008-03-18,24.42,25.30,24.03,24.90,1893100
2008-03-14,26.85,26.93,24.60,25.46,1751900
2008-03-13,26.55,26.92,26.00,26.30,1620600
2008-03-12,27.50,27.75,26.51,27.19,2040400
2008-03-11,26.60,27.38,26.31,27.35,2645600
)

RegExMatch = mU)(.*),(.*),(.*),(.*),(.*),(.*)\n
To = $1,$2,$3,$5,$4`n
var := RegExReplace(var . "`n", RegExMatch, To)
MsgBox %var%


Output:
Quote:
Date,Open,High,Adj Close,Low
2008-03-20,23.03,23.65,23.00,22.92
2008-03-19,24.94,25.16,23.70,23.70
2008-03-18,24.42,25.30,24.90,24.03
2008-03-14,26.85,26.93,25.46,24.60
2008-03-13,26.55,26.92,26.30,26.00
2008-03-12,27.50,27.75,27.19,26.51
2008-03-11,26.60,27.38,27.35,26.31

What`s added:
  • The m-Option lets the RegEx match to every line separate.
  • The U-Option makes dot star ungreedy.
  • The added new line `n at end of string in RegExReplace function is needed for last line.
Back to top
View user's profile Send private message Send e-mail
evan
Guest





PostPosted: Fri Mar 28, 2008 9:42 am    Post subject: Reply with quote

i have no clue how to use that syntax @@
the lines i usually use is around 10-50(max)
its not going to take more than 0.1 second to finish the job with replace, split etc

but i am interested in learning something better
RegExMatch sounds a good thing to learn in order to speed up my memory reading/writing
Back to top
rockit0



Joined: 06 Oct 2006
Posts: 22

PostPosted: Mon Mar 31, 2008 2:14 pm    Post subject: Reply with quote

EXCELENT

Thank's Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group