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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:13:09+00:00 2026-05-28T11:13:09+00:00

I’m writing some regex to match lines which contain numeric elements padded with spaces,

  • 0

I’m writing some regex to match lines which contain numeric elements padded with spaces, like -2.45. The regex for this is simple enough:

/(\s*-?\d+\.\d{2})/

However, I have the additional constraint that the whole chunk is limited to exactly seven characters. I can modify the expression to constrain the leading space and digits to within their theoretical maximums:

/(\s{0,3}-?\d{1,4}\.\d{2})/

But this is not the solution, as the \s{0,3} matches independently of the \d{1,4}, so the whole thing could match a chunk anywhere from four to eleven characters.

Is there any way I can constrain a whole group like this to a fixed length?

Edit:

To clarify, I’m processing lines with three of these seven character groups separated with three spaces, so the larger regex goes along the lines of:

/^(fixed length stuff at start of line)(7 char chunk)\s{3}(2nd 7 char chunk)\s{3}(3rd 7 char chunk)$/

Mixed in are other lines which have only one or two of these numeric groups in, lines with presentational junk, and lines with other (possibly unknowable) content so I’m looking to be quite precise in what I match.

  • 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-05-28T11:13:10+00:00Added an answer on May 28, 2026 at 11:13 am

    You can use a lookahead assertion (and you don’t need the parentheses):

    /(?=[\s\d-]{4}\.\d{2})\s*-?\d+\.\d{2}/
    

    You might need some anchors around the regex to ensure that you don’t match beyond the seven characters, depending on what delimits these elements, for example

    /(?=[\s\d-]{4}\.\d{2}\b)\s*-?\d+\.\d{2}\b/
    

    to ensure that the number actually ends after the \.d{2} part.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string

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.