?
Solved

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

Posted on 2008-06-17
6
Medium Priority
?
291 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:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 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 1000 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
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.

 
LVL 3

Author Comment

by:Neil Thompson
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:Neil Thompson
ID: 21802993
got it, used preg_match in the end
0
 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 31467877
Thanks
Neil
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

741 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