Re: preg_match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jon wrote:
preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single, $from_invoice);

The text has "Charges" then a variable amount of spaces a previously picked
decimal number" x " (and the data I want)" "

is this correct or am I missing something?  It seems to work sometimes and
not others and I have not quite figured out what makes it fail.

The error I get is
Warning: preg_match_all(): unknown modifier '#' in "file"

Gracious, did you start a long thread.  Several workable solutions are provided.

I'd like to offer some general advice, I learned from experience.

I never use "/" as the delimiter; there are too many chances for errors. I generally use "%", unless my haystack can possible contain it. It is easier to spot syntax errors, for example. Otherwise, I use a delimiter that cannot be in my haystack and is not a regex reserved character. Rarely is there a delimiter that is both in the haystack and is a reserved character; if so, I just use literal code "\" as required.

I never use repeated special characters e.g., "\s\s" use "*", "+" or "{n,m}" as needed.

I rarely use "dot all" [e.g., "."] it accepts everything and can make testing very difficult. Invariably, there is a combination I never thought of to test. I use explicit statements for everything that can be in my haystack [e.g., \d, \w, [a-z], [0-9], \s, \S, etc.]

I always use the Reg Coach for complicated patterns and build and test the pattern one step at a time.


Al.........

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux