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
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,
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Where did the @ symbols go?
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
$body=~s/@//g;
I now have this
.+?(buy|sell)\s+(.+?)\s+([
which matches but it does not save the whole number in $5 and $7
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){
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ozo:
this is almost there, it did not skip over the @ in "EUR/JPY @"
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
with no @Breakout Trade: SELL EUR/JPY 101.42 Stop 101.77 Target #1 101.17 Target #2 100.97 Target #3
100.82
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
ASKER
thank you.
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?