• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

preg_match in PHP

Any idea what this preg_match want to do ? Tks

if(!preg_match(“/^[4]{1,1}[0-9]{12,15}$/”,$value))
0
AXISHK
Asked:
AXISHK
3 Solutions
 
Radek BaranowskiFull-stack Java DeveloperCommented:
http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm

it matches a string that
begins (^) with exactly one ({1,1}) "4" then is followed by 12 to 15 digits 0-9

so, the pattern like:

41234567890123

hope this helps!
0
 
Dan CraciunIT ConsultantCommented:
I think the string was done so you can quickly change the amounts of digits at the beginning, or else {1,1} is meaningless.
As is, the pattern can be written as
^4\d{12,15}$

HTH,
Dan
0
 
AXISHKAuthor Commented:
^4\d{12,15}$

Does it mean starting with '4", following by 12 - 15 digit number ? Tks
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Radek BaranowskiFull-stack Java DeveloperCommented:
yes.
0
 
Ray PaseurCommented:
There is one other problem.  The apparent double quote wrapping the regular expression are not, in fact, quotes.  They may be something that wormed its way in from cut/paste with Microsoft word?  You may want to read this article about how PHP handles quote marks.  It's an important part of the language with many effects on the meaning of the code.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

You may find that your regular expressions are easier to craft and understand if you write them like this, with comments to explain the intent of each segment of the expression:
$rgx 
= '#'           // REGEX DELIMITER (REQUIRED AT FRONT AND BACK OF EXPRESSION)
. '^'           // AT THE START OF THE STRING
. '[4]'         // CHARACTER CLASS THAT INCLUDES ONLY "4"
. '{1,1}'       // EXACTLY ONE OF THIS CHARACTER CLASS
. '[0-9]'       // CHARACTER CLASS THAT INCLUDES DIGITS 0-9
. '{12,15}'     // BETWEEN 12 AND 15 OF THE DIGITS
. '$'           // AT THE END OF THE STRING
. '#'           // REGEX DELIMITER
;

Open in new window

In the instant case this looks like  the regex is intended to match certain kinds of credit card numbers.
0
 
AXISHKAuthor Commented:
Tks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now