NoizeBit

RegEx combination

8 posts in this topic

#1 ·  Posted (edited)

Greetings to all the RegEx gurus out there :lol:

I'm trying my best to learn it and already started doing so, although it'd be nice to have some help with an expression.

I have these created on a regex generator site in pcre (php): 

/^.*Instrument.*$

/^((?![2][8]-[0][8]-[1][5]).)*$ /gm

These are working great on their own. Could you guys help me how to combine them into one expression if possible and convert it to StringRegExpReplace?

Edited by NoizeBit

Share this post


Link to post
Share on other sites



Input: 

Instrument,Type,Asset,Order #,Order Time,Invested,Target Price,Expiry Price,Expiry Time,Return,
High / Low,High,GBP/USD,35949250,01-09-15 17:52:12,24.00,1.53088,1.53147,01-09-15 18:30:00,43.68,
High / Low,Low,EUR/USD,35824912,28-08-15 17:50:57,24.00,1.12031,1.11823,28-08-15 18:30:00,43.92,
High / Low,High,EUR/JPY,35693949,26-08-15 11:51:27,24.00,136.331,136.30800,26-08-15 12:30:00,0.00,

Output:

Instrument,Type,Asset,Order #,Order Time,Invested,Target Price,Expiry Price,Expiry Time,Return,
High / Low,Low,EUR/USD,35824912,28-08-15 17:50:57,24.00,1.12031,1.11823,28-08-15 18:30:00,43.92,

I'd like to delete all the lines not containing the string "28-08-15".

Share this post


Link to post
Share on other sites

?

$string = "Instrument,Type,Asset,Order #,Order Time,Invested,Target Price,Expiry Price,Expiry Time,Return," & @CRLF & _
"High / Low,High,GBP/USD,35949250,01-09-15 17:52:12,24.00,1.53088,1.53147,01-09-15 18:30:00,43.68," & @CRLF & _
"High / Low,Low,EUR/USD,35824912,28-08-15 17:50:57,24.00,1.12031,1.11823,28-08-15 18:30:00,43.92," & @CRLF & _
"High / Low,High,EUR/JPY,35693949,26-08-15 11:51:27,24.00,136.331,136.30800,26-08-15 12:30:00,0.00,"


$output = StringRegExpReplace($string, "\R.+(?!28-08-15)(\d{2}-){2}\d{2}\V+", "")
ConsoleWrite($output)

 

Share this post


Link to post
Share on other sites

NoiseBit,

If this is related to your screen scraping ditty from yesterday, perhaps you would like to substitute todays date using as variable...

$string = "Instrument,Type,Asset,Order #,Order Time,Invested,Target Price,Expiry Price,Expiry Time,Return," & @CRLF & _
"High / Low,High,GBP/USD,35949250,08-09-15 17:52:12,24.00,1.53088,1.53147,08-09-15 18:30:00,43.68," & @CRLF & _
"High / Low,High,GBP/USD,35949250,01-09-15 17:52:12,24.00,1.53088,1.53147,01-09-15 18:30:00,43.68," & @CRLF & _
"High / Low,Low,EUR/USD,35824912,28-08-15 17:50:57,24.00,1.12031,1.11823,28-08-15 18:30:00,43.92," & @CRLF & _
"High / Low,Low,EUR/USD,35824912,08-09-15 17:50:57,24.00,1.12031,1.11823,08-09-15 18:30:00,43.92," & @CRLF & _
"High / Low,High,EUR/JPY,35693949,26-08-15 11:51:27,24.00,136.331,136.30800,26-08-15 12:30:00,0.00,"

local $sToday = @MDAY & '-' & @MON & '-' & stringright(@YEAR,2)

$output = StringRegExpReplace($string, "\R.+(?!" & $sToday & ")(\d{2}-){2}\d{2}\V+", "")
ConsoleWrite($output & @LF)

@jguinch - I think you just answered a problem I'm having with a regex...thanks 


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

NoiseBit,

If this is related to your screen scraping ditty from yesterday, perhaps you would like to substitute todays date using as variable...

$string = "Instrument,Type,Asset,Order #,Order Time,Invested,Target Price,Expiry Price,Expiry Time,Return," & @CRLF & _
"High / Low,High,GBP/USD,35949250,08-09-15 17:52:12,24.00,1.53088,1.53147,08-09-15 18:30:00,43.68," & @CRLF & _
"High / Low,High,GBP/USD,35949250,01-09-15 17:52:12,24.00,1.53088,1.53147,01-09-15 18:30:00,43.68," & @CRLF & _
"High / Low,Low,EUR/USD,35824912,28-08-15 17:50:57,24.00,1.12031,1.11823,28-08-15 18:30:00,43.92," & @CRLF & _
"High / Low,Low,EUR/USD,35824912,08-09-15 17:50:57,24.00,1.12031,1.11823,08-09-15 18:30:00,43.92," & @CRLF & _
"High / Low,High,EUR/JPY,35693949,26-08-15 11:51:27,24.00,136.331,136.30800,26-08-15 12:30:00,0.00,"

local $sToday = @MDAY & '-' & @MON & '-' & stringright(@YEAR,2)

$output = StringRegExpReplace($string, "\R.+(?!" & $sToday & ")(\d{2}-){2}\d{2}\V+", "")
ConsoleWrite($output & @LF)

@jguinch - I think you just answered a problem I'm having with a regex...thanks 

@kylomas - you're right, that was the plan, thanks ^_^

@jguinch - thanks a lot for helping me out ;)

Share this post


Link to post
Share on other sites

You're welcome, both.

@NoizeBit : next time, try to give us all the informations in the first message, you will have more chances to get answers if the explanation is clear enough.

Alright, will do.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now