Solved

regex + price

Posted on 2004-03-31
6
222 Views
Last Modified: 2011-10-03
Hi folks,

Here is some string I have to evaluate against a regex:

piece_1_Y_100_Motherboard
piece_2_Y_189_Processor
piece_7_N_0.1_OS
piece_8_N_0.1_Monitoring

The regex I use is:
ereg("piece_([0-9]+)_(Y|N)_([^_]+)_(.+)", $key, $regs)
Where:
// $regs[0] = $key = le nom de la variable au complet
// $regs[1] = position
// $regs[2] = Y ou N (inFormula)
// $regs[3] = price
// $regs[4] = Component's name

The problem I have is when the price contains a dot in it (like the last 2 string I gave above).
I only get 0
I tried changing ([^_]+) to ([0-9.]+) without luck

If someone could explain me what's wrong with this, I'd appreciate it.

Thanks.
0
Comment
Question by:kuist
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10729030
This works....

ereg("piece_([0-9]+)_(Y|N)_(((([0-9]+).([0-9]+))|([0-9]+) )*)", $key, $regs)
0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 125 total points
ID: 10729082

I think this is what you wanted......

ereg("piece_([0-9]+)_(Y|N)_(([0-9]+.[0-9]+)|([0-9]+))", $key, $regs)

0
 

Author Comment

by:kuist
ID: 10729530
How do I access the price from ereg("piece_([0-9]+)_(Y|N)_(([0-9]+.[0-9]+)|([0-9]+))", $key, $regs) ??

thanks
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10730242

<?php

//$msg = "piece_1_Y_100_Motherboard";
$msg = "piece_7_N_0.1_OS";

if (ereg ("piece_([0-9]+)_(Y|N)_(([0-9]+.[0-9]+)|([0-9]+))", $msg, $regs)) {
  echo "$regs[3] -- $regs[2] -- $regs[1]";
} else {
  echo "Invalid  format";
}

?>
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10730246

<?php

//$msg = "piece_1_Y_100_Motherboard";
$msg = "piece_7_N_0.1_OS";

if (ereg ("piece_([0-9]+)_(Y|N)_(([0-9]+.[0-9]+)|([0-9]+))", $msg, $regs)) {
  echo "$regs[3] -- $regs[2] -- $regs[1]";
} else {
  echo "Invalid  format";
}

print "\nprice = $regs[3]\n";
?>
0
 

Author Comment

by:kuist
ID: 10733221
the price it gives me is 0_1 instead of 0.1

any idea why ?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question