Question:

New to Regex. Could someone help me with my first example? Thanks.?

by  |  earlier

0 LIKES UnLike

What is the regex expression for this:

I want to extract a 12 digit number. The word "itemZ" precedes this number, and the letters "QQ" follows this number. I am looking for all the occurrence of these 12 digit numbers and I want the results to be put into an array. I am doing this in PHP and I need to use preg_match_all, but the regex expression for any pc language will probably work.

 Tags:

   Report

2 ANSWERS


  1. You can try

    www.regexplib.com

    The site has a huge collection of Regex


  2. Search the internet for regular expression calculators. They help you develop a regex and visually see the results.

    Your first part is simple:  \d{12} should give you your 12 digit number.

    The second part is to put your text before and after:

    itemZ\d{12}QQ

    But you only want the number so you put parens around this part:

    itemZ(\d{12})QQ

    Geting all results into an array - this I have to leave for you as I am not familar with the PHP regex engine.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.