Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9100447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:52:01+00:00 2026-06-17T00:52:01+00:00

I need to extract data from unstructured string coming from a sms The data

  • 0

I need to extract data from unstructured string coming from a sms

The data I need to extract is the following

Code: This a 5 letter alphanumeric string it must contain at least one digit

Identity document: This is a numeric string between 5 and 8 characters, valid formats are:

V55555555
E55555555
55555
55 555
E55 555 555
55 555 555
5 555 555
555 555

The data I need to extract could be in any position in the string, I have normalized the string,
replaced duplicate spaces by only one, and deleting anything that is not a space, number and letter

Samples

1. resuelvete 15C20 Pdero Perez c.i. V55.555.555,
2. Pedro Perez resuelvete 15c20 55 555 555,
3. 15c20 Resuelvete 555555 Pedro Perez,
4. Resuelvete 555555 Pedro Perez 15c20

For the code part I’ve tried this regex:

$regex = '/([a-zA-Z0-9]{5})/i';

I also tried this: $regex = '(?=.{5})(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[a-zA-Z\d]';, that I see here but it’s not working (I must say I don’t totally understand this regex)

But it’s not working, its returnig the first five characters of the string, I need it to return in this examples 15c20

For the Identity document part I’ve tried the following:

// This not work with spaces
$regex = "/(V|E)?(\d{5,8})/i";

// This not work without spaces
//This fail in first case returning only 7 digits instead of 8
// Also fails in cases  3 and 4,  does not match anything
$regex = "/(V|E)?(\d{1,2}? ?\d{3} ?\d{3})/i";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:52:03+00:00Added an answer on June 17, 2026 at 12:52 am

    [EDIT] I changed all \w‘s in the following regex pattern into [a-zA-Z0-9] because \w includes the underscore ( _ ) character as well, which I forgot at the time I wrote this answer.

    For the code you can use something like

    ~\b(?=[a-zA-Z0-9]{5}\b)[a-zA-Z0-9]*\d[a-zA-Z0-9]*~
    

    which can be broken into

    \b                  # a word boundary (beginning of word in this case)
    (?=                 # from here on...
        [a-zA-Z0-9]{5}  # 5 alphanumeric characters (a-z,A-Z,0-9)
        \b              # followed by a word boundary (end of word)
    )
    [a-zA-Z0-9]*        # 0 or more alphanumeric characters (a-z,A-Z,0-9)
    \d                  # a decimal
    [a-zA-Z0-9]*        # 0 or more alphanumeric characters (a-z,A-Z,0-9)
    

    For the id document… If there are no possible groupings other than the examples you provided, you can use something like

    '~(?<=\b|\bE|\bV)(?=[\d\ .]{5,10}\b)(
        \d{8}|
        \d{5}|
        \d{3}[\ .]\d{3}|
        \d{2}([\ .])\d{3}(\2\d{3})?|
        \d([\ .])\d{3}\4\d{3}
    )~x'
    

    and this says

    (?<=                        # preceded by
        \b|                     # a word boundary (beginning of word) or
        \bE|                    # a word boundary (beginning of word) and E or
        \bV                     # a word boundary (beginning of word) and V
    )
    (?=                         # from here on...
        [\d\ .]{5,10}           # a group consisting of only decimals, spaces and dots 
        \b                      # followed by a word boundary (end of word)
    )
    (                           # either:
        \d{8}|                  # an 8 digit number
        \d{5}|                  # a 5 digit number
        \d{3}[\ .]\d{3}|        # a 3 digit number, space or dot, a 3 digit number
        \d{2}([\ .])\d{3}       # a 2 digit number, space or dot, a 3 digit number
        (                       # optionally...
            \2                  # previous sign (space or dot)
            \d{3}               # a 3 digit number
        )?| 
        \d([\ .])\d{3}\4\d{3}   # a 1 digit number, space or dot, a 3 digit number, previous sign, a 3 digit number
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need extract data from a string. Heres an example: Mozilla/5.0 (Macintosh; U; PPC
I need to extract data from such code: <div class=rateCalc_InfoLine2> <span style=font-size:12px;> Text1 -
I need to extract certain data from a file, but this file is formatted
I need extract data from a JSON array, format '[[[1,2,3]],[[1,2,3],[1,2,3]],string]' in Qt. logically it's
i need to extract data from this array of objects { data: [ {
I've got the following three strings that I need to extract some data from
I am trying to extract data from this String: Hello there. Blah blahblah blah
I need to extract the pricing data from a form. The form contain several
I have this html data which I need to parse to extract data from
I need to extract data from a structure and put it into a list,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.