Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regex + price

Posted on 2004-03-31
6
Medium Priority
?
227 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 375 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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