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

samjAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
Try this version:

if ($body =~m{(BUY|SELL) ([^@ ]+) @ ([\d.]+) [^@]* @ ([\d.]+) [^@]* @ ([\d.]+) [^@]* @ ([\d.]+) [^@]* @ ([\d.]+)}i){

Open in new window

0
 
Robert SchuttSoftware EngineerCommented:
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?
0
 
samjAuthor Commented:
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

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
käµfm³d 👽Commented:
Where did the @ symbols go?
0
 
samjAuthor Commented:
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
0
 
samjAuthor Commented:
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

0
 
ozoConnect With a Mentor Commented:
In absence of the @ you'd need some other way to specify what to skip over.  e.g.

/.+?(buy|sell)\s+(.+?)\s+([\d.]+).+?([\d.]+).+?\#1.*?([\d.]+).+?\#2.*?([\d.]+).+?\#3.*?([\d.]+)/ismxg
0
 
samjAuthor Commented:
ozo:
this is almost there, it did not skip over the @  in "EUR/JPY @"
0
 
ozoCommented:
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

0
 
samjAuthor Commented:
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

0
 
samjAuthor Commented:
thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.