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 8417515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:04:11+00:00 2026-06-10T02:04:11+00:00

I have a problem involving PHP and regex. I have some files and need

  • 0

I have a problem involving PHP and regex.

I have some files and need to capture some of the names. But there’s one part that are not in all.

Example files:
D.SAE.IND.001.TME.BR.SER.20120729
D.SUI.IND.003.TMC.GER.TOT.201206
D.SAE.LIS.008.AGE.APS.SER.45D.20120713

Note that the last file has a part (“45D”) that is optional.
I need to get every group. I was using the following regex:

preg_match('/D\.(?P<font>[\w]*)\.(?P<tipo>[\w]*)\.(?P<numberLevel>[\d]*)\.(?P<indicator>[\w]*)\.(?P<nameLevel>[\w]*)\.(?P<group>[\w]*)\.(?P<id>[\d]*)/i', $arrInput , $result);

The problem is that optional part (eg the latest file – “45D”).
I need this result:

D.SAE.IND.001.TME.BR.SER.20120729
$result[‘fonte’] = ‘SAE’
$result[‘tipo’] = ‘IND’
$result[‘numberLevel’] = ‘001’
$result[‘indicator’] = ‘TME’
$result[‘nameLevel’] = ‘BR’
$result[‘group’] = ‘SER’
$result[‘op’] = ”
$result[‘id’] = ‘20120729’

D.SAE.LIS.008.AGE.APS.SER.45D.20120713
$result[‘fonte’] = ‘SAE’
$result[‘tipo’] = ‘LIS’
$result[‘numberLevel’] = ‘008’
$result[‘indicator’] = ‘AGE’
$result[‘nameLevel’] = ‘APS’
$result[‘group’] = ‘SER’
$result[‘op’] = ’45D’
$result[‘id’] = ‘20120713’

Thank you in advance for help.

  • 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-10T02:04:13+00:00Added an answer on June 10, 2026 at 2:04 am

    This works for me:

    /D\.(?P<font>[\w]*)\.(?P<tipo>[\w]*)\.(?P<numberLevel>[\d]*)\.(?P<indicator>[\w]*)\.(?P<nameLevel>[\w]*)\.(?P<group>[\w]*)\.(?:(?P<op>.*)\.)?(?P<id>[\d]*)/i
    

    The key is adding:

    (?:(?P<op>.*)\.)?
    

    Before the id group.

    Edit: Added the ?: to make the grouping non-capturing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some tricky generic type problem involving reflection. Here's the code. public @interface
I have a problem, I need to edit an xml file using php, based
Hello I seem to be having some problem involving counting in Django. I have
I have some PHP AJAX code that is supposed to validate some parameters sent
I have a conceptually simple problem involving Google Analytics and Tomcat, but I cannot
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem developing with live555. I already build the lib-files and example projects
I have a problem involving setinterval. It's probably best to show an example so
I have a problem with a subquery involving IPV4 addresses stored in MySQL (MySQL
I have tried to write a basic merge sort in PHP involving a small

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.