Jump to content

Regular expression for 4 digit number with two decimal places


rahulag38

Recommended Posts

Hello,

  I need the regular expression for xxxx.xx . The code i am using is showing error.

 

My code:

 

$pattern='^\d{1,4}(\.\d{1,2})?$';

preg_match_all($pattern, $stringss, $matches);

 

The error i am getting:

Warning: preg_match_all() [function.preg-match-all]: No ending delimiter '^' found in /home/flightde/public_html/test.php  on line 3

$pattern='/^\d{1,4}(\.\d{1,2})?$/';

 

(don't forget your / delimiters)

 

Thanxs a lot..

 

Also what would be the reg ex for -

1. "[2] = xxxx.xx"

2."[2]=xxxx.xx"

 

i.e everything between the  quotes " " including the square brackets ,"=" sign and the digit "2", where X = number between 0-9. The diff btw first and second is that spaces are eliminated :)

\[\d\]\s?=\s?\d{1,4}\.\d{1,2}\s?

 

Thanxs a lot for replying..

 

The digit in the  square bracket has to be "2" and not just ant digit :).

Also could not understand why have you used "?" . I want the exact pattern match and nothing optional

\[\d\]\s?=\s?\d{1,4}\.\d{1,2}\s?

 

Thanxs a lot for replying..

 

The digit in the  square bracket has to be "2" and not just ant digit :).

Also could not understand why have you used "?" . I want the exact pattern match and nothing optional

 

And the pattern would be :

 

"[2] = 'xxxx.xx'"

 

Every thing between double quotes (including the single quote surrounding the digits)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.