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

  • Home
  • SEARCH
  • 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 8272915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:17:36+00:00 2026-06-08T07:17:36+00:00

I have inherited a perl script that pulls data out of some files. The

  • 0

I have inherited a perl script that pulls data out of some files. The whole script works fine but recently some engineers have been putting in more than one number for a certain spot that usually took one number, so the output is not showing all of what is expected.

Sample input:

CRXXXX: "Then some text"

CRs XXXX, XXXX, XX, XXX

CRXXX "Some Text"

Currently this regex statement I have pulls out the number after the CR, but if given then second line of sample input it prints "s XXXX, XXXX, XX, XXX" instead of the wanted "XXXX XXXX XX XXX"

I am very new to perl and am struggling to figure out how to alter this regex to work on all of the inputs.

 $temp_comment =~ s/\s[cC][rR][-\s:;]*([\d])/\n$1/mg;

Thanks in advance!

Brock

  • 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-08T07:17:37+00:00Added an answer on June 8, 2026 at 7:17 am

    For sample data like:

    my $temp_comment =
    'CR1234: "Then some text"
     CRs 2345, 3456, 45, 567
     CR678 "Some Text"';
    

    try:

    $temp_comment =~ s/(,)|[^\d\n]+/$1?' ':''/semg;
    

    or, if you want to stay close to the string templates:

    $temp_comment =~ s/ ^                 # multi-line mode, line start
                        \s*               # leading blanks?
                        CR                # CR tag
                        \D*               # non-number stuff
                         (                  # start capture group
                          (?:\d+ [,\s]*)+   # find (number, comma, space) groups
                         )                  # end capture group
                        \D*               # skip remaining non-number stuff
                        $                 # multi-line mode, line end
                      /$1/mxg;            # set multi-line mode + regex comments "x" 
    

    but you’d have to remove the commas in the number group in a subsequent step.

    $temp_comment =~ tr/,//d;             # remove commas in the whole string
    

    or

    $temp_comment =~ s/(?<=\d),(?=\s\d)//g;  # remove commas between numbers '11, 22'
    

    For “single step”, you have to use the /e modifier:

    $temp_comment =~ s{ ^                 # line start
                        \s*               # leading blanks?
                        CR                # CR tag
                        \D*               # non-number stuff
                        ((?:\d+ [,\s]*)+) # single or group of numbers
                        \D*               # non number stuff
                        $                 # line end
                      }
                      {do{(local$_=$1)=~y/,//d;$_}}mxeg;
    

    This will, on the data above, result in:

    1234
    2345 3456 45 567
    678 
    

    But really, please use, if possible, the simpler two step approach. The latter regex might be a maintainance nightmare for your successors.

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

Sidebar

Related Questions

I have inherited a web project that is perl based and I'm attempting to
I have inherited a classic asp application that had over 800 files in the
I have seen a usage perl script used to pre-split data Link Question> How
I have inherited a project that logs data from a single board computer to
I have inherited some code that isn't quite working ... I have jsp which
I have inherited some verbose, repetitious code that I am trying to refactor. The
I have a PERL script that is creating a lot of sockets (around 700
I have inherited some code that will eventually be part of an API call.
I have a Perl script, which parses datafile and writes 5 output files filled
I have inherited some code (that happens a lot!) which looks a bit like

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.