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

Link to comment
Share on other sites

$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 :)

Link to comment
Share on other sites

\[\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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.