Solved

check my variables with this regex? 1[0-9]{6}[xX0-9]{1}

Posted on 2008-06-17
6
248 Views
Last Modified: 2010-04-21
Hi

I'm moving some code from Java to PHP and I have a variable (  $paymentReference1  ) that I need to check againse this regex (  1[0-9]{6}[xX0-9]{1}  )

Can someone show me what to do please and possible explain the regex a little

Many thanks
Neil
0
Comment
Question by:NeilT
  • 3
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 21800614
perl -MYAPE::Regex::Explain -e "print YAPE::Regex::Explain->new(qr(1[0-9]{6}[xX0-9]{1}))->explain"
The regular expression:

(?-imsx:1[0-9]{6}[xX0-9]{1})

matches as follows:
 
NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  1                        '1'
----------------------------------------------------------------------
  [0-9]{6}                 any character of: '0' to '9' (6 times)
----------------------------------------------------------------------
  [xX0-9]{1}               any character of: 'x', 'X', '0' to '9' (1
                           times)
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
0
 
LVL 5

Assisted Solution

by:mms_master
mms_master earned 250 total points
ID: 21800623
Hi,

Im assuming regex is a regular expression function in java. The PHP equivelant would be ereg() and eregi(); ereg is case sensitive and eregi isnt. More info at the links below.

ereg():
http://uk.php.net/manual/en/function.ereg.php

eregi():
http://uk.php.net/manual/en/function.eregi.php

Theres an example below of how you can use them.

mms_master
<?php
 

$paymentReference1 = "10257929";
 

if (ereg("1[0-9]{6}[xX0-9]{1}", $paymentReference1)) {

    echo "They match!";

} else {

    echo "They don't match!";

}
 

?>

Open in new window

0
 
LVL 5

Expert Comment

by:mms_master
ID: 21800676
Here is a guide for regular expressions:
http://www.zytrax.com/tech/web/regex.htm

mms_master
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 3

Author Comment

by:NeilT
ID: 21802634
Still cant get this to work, probably doing something wrong

Using as a test:

This should come back as pass
error_log(ereg("10948055", "1[0-9]{6}[xX0-9]{1}"));

This should Fail
error_log(ereg("50948055", "1[0-9]{6}[xX0-9]{1}"));

Neither seem to do anything?

Neil



0
 
LVL 3

Author Comment

by:NeilT
ID: 21802993
got it, used preg_match in the end
0
 
LVL 3

Author Closing Comment

by:NeilT
ID: 31467877
Thanks
Neil
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now