SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Dabrowski's Avatar
    Join Date
    Apr 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    General Regex Problem

    I still have not gotten any regex to work properly. I typically get Unknown Delimiter.

    Right now, I just want to make sure that a $subject has a valid dollar value.

    239.38 , 30.00 , 4.34 , etc.

    How come this code gives me an error


    PHP Code:
    if (preg_match("(\d*)\.(\d{2}$)""43.44")) {
       echo 
    "A match was found.";
    } else {
       echo 
    "A match was not found.";

    While the pattern
    Code:
    (\d*)\.(\d{2}$)
    seems to work in a regex tester ( http://www.regexlib.com/RETester.aspx) ?

  2. #2
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,188
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Because you need to put a delimiter at the start and end of the regex.
    This delimiter need to be commented out if it is inside the regex.

    If you add a / in start and end of your regex it will work.
    /(\d*)\.(\d{2}$)/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •