Solved

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

Posted on 2008-06-17
6
289 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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.

728 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