[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-06-17
6
Medium Priority
?
300 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
  • 3
  • 2
6 Comments
 
LVL 85

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
Industry Leaders: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 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