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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:32:59+00:00 2026-06-11T15:32:59+00:00

split /PATTERN/,EXPR I read the following in a book, When you use a pattern

  • 0
split /PATTERN/,EXPR

I read the following in a book,

When you use a pattern in split, be sure to avoid memory parantheses
in the pattern since these trigger seperator retention mode.

I can’t seem to find the documentation which explains this in detail. Could someone please explain Seperator Retention Mode and its possible usage briefly?

  • 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-11T15:33:00+00:00Added an answer on June 11, 2026 at 3:33 pm

    This is documented in perldoc -f split towards the end (in-code commentary is my own):

    If the PATTERN contains capturing groups, then for each separator,
    an additional field is produced for each substring captured by a group
    (in the order in which the groups are specified, as per
    backreferences); if any group does not match, then it captures the
    undef value instead of a substring. Also, note that any such
    additional field is produced whenever there is a separator (that is,
    whenever a split occurs), and such an additional field does not count
    towards the LIMIT. Consider the following expressions evaluated in
    list context (each returned list is provided in the associated
    comment):

    split(/-|,/, "1-10,20", 3)       # ('1', '10', '20')
                                     # No retention, '-', ',' consumed
    
    split(/(-|,)/, "1-10,20", 3)     # ('1', '-', '10', ',', '20')
                                     # Split on and retain '-' or ','
                                     # 5 elements returned
    
    split(/-|(,)/, "1-10,20", 3)     # ('1', undef, '10', ',', '20')
                                     # undef because '-' matches
    
    split(/(-)|,/, "1-10,20", 3)     # ('1', '-', '10', undef, '20')
                                     # undef because ',' matches
    
    split(/(-)|(,)/, "1-10,20", 3)   # ('1', '-', undef, '10', undef, ',', '20')
                                     # one match per capturing group. (-) matches -, but
                                     # (,) returns undef on trying to match -.
                                     # 7 elements (!)
    

    So, two interesting quirks that may catch out the unwary:

    • The generation of undefs in list context whenever a capturing group does not match, but something else in PATTERN does

    • You might split with a capture group, specifying LIMIT as $n, and the resultant list has more than $n elements

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

Sidebar

Related Questions

I am trying to use a simple split to break up the following string:
According to the perldoc , the syntax for split is: split /PATTERN/,EXPR,LIMIT But the
Is it possible to build a regexp for use with Javas Pattern.split(..) method to
string pattern = @(if)|(\()|(\))|(\,); string str = IF(SUM(IRS5555.IRs001)==IRS5555.IRS001,10,20); string[] substrings = Regex.Split(str,pattern,RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase)
I am having problem to split string in java. it gives java.util.regex.Pattern.error . String
Can split(string, array, separator) in awk use sequence of whitespaces as the separator (or
I'd like to split a string that has a certain repeating pattern, for example:
I want to know when we need to use the abstract factory pattern. Here
I have the following string 3/4Ton. I want to split it as --> word[1]
I'd like to split a string with using pattern like this: it starts and

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.