Link to home
Start Free TrialLog in
Avatar of samj
samj

asked on

active perl regex

Hi
I have this string which I need to extract the bold text from it using regex in active perl.
the regex I include is not cutting it. pls. help. thx

Breakout Trade: SELL EUR/JPY @ 101.42 Stop @ 101.77 Target #1 @ 101.17 Target #2 @ 100.97 Target #3 @ 100.82
if ($body =~m{.+?(buy|sell)\s+(.+?)\s+@\s+([\d.]+)\s+stop.*?([\d.]+).+?@\s([\d.]+).+?@\s([\d.]+).+?@\s([\d.]+)}ismxg){
						push @entries, {
							action => $1,
							cur    => $2,
							price  => $3,
							sl     => $4,
							t1     => $5,
							t2     => $6,
							t3     => $7,
						};

Open in new window

Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

sometimes \s has a + other times not, so if there are several spaces it will fail.

I tried it as shown above (with 1 space in between all words/numbers), printed out $1 etc, and they are ok.

If this is not it, maybe the problem is in the push or the following part where you process @entries?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samj
samj

ASKER

I tried fixing the \s to \s+ for no avail.
I tried the code supplied by kaufmed for no avail.

here is the exact data
Breakout Trade: SELL EUR/JPY  101.42 Stop  101.77 Target #1  101.17 Target #2  100.97 Target #3
 100.82

Open in new window

Where did the @ symbols go?
Avatar of samj

ASKER

it has been removed in an earlier code line.
$body=~s/@//g;
I now have this

.+?(buy|sell)\s+(.+?)\s+([\d.]+).+?([\d.]+).+?([\d.]+).+?([\d.]+).+?([\d.]+)

which matches but it does not save the whole number in $5 and $7
Avatar of samj

ASKER

I ended up doing this which worked.
$body=~s/@|Target\s+#\d\s+@//g; 
if ($body =~m{.+?(buy|sell)\s+(.+?)\s+([\d.]+).+?([\d.]+).+?([\d.]+).+?([\d.]+).+?([\d.]+)}ismxg){

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samj

ASKER

ozo:
this is almost there, it did not skip over the @  in "EUR/JPY @"
You just told us that the exact data to be matched was
Breakout Trade: SELL EUR/JPY  101.42 Stop  101.77 Target #1  101.17 Target #2  100.97 Target #3
 100.82

Open in new window

with no @

Breakout Trade: SELL EUR/JPY  101.42 Stop  101.77 Target #1  101.17 Target #2  100.97 Target #3
 100.82

Open in new window

Avatar of samj

ASKER

sorry Ozo. it is my bad. here is the exact data.


Breakout Trade: SELL EUR/JPY @ 101.42 Stop @ 101.77 Target #1 @ 101.17 Target #2 @ 100.97 Target #3
@ 100.82

Open in new window

Avatar of samj

ASKER

thank you.