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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:15:32+00:00 2026-06-15T12:15:32+00:00

I want to build a pattern to exchange integer numbers which are the only

  • 0

I want to build a pattern to exchange integer numbers which are the only thing on the line

If there is a word on the same line as the integer I do not want to change anything.

I tried $pattern = '/(.)[0-9][0-9](.)/';
but this doesn’t work well for me

and when I try for example $pattern = '/1(.)2(.)3(.)/'; it will replace the only single numbers which I will put in pattern

I want to replace example subject of this

subject = "
1
2
3
4
5
6
7
8
9
10
"

the numbers must be integer not decimal and amouth of them are random but there musn’t be any text on the same line as the number?

Any ideas?

  • 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-15T12:15:33+00:00Added an answer on June 15, 2026 at 12:15 pm

    What you need is multi-line mode m. If you use it ^ matches at the beginning and $ matches at the end of each line. Then use \d+ for an arbitrarily long integer number:

    /^[ \t]*\d+[ \t]*$/m
    

    The [ \t]* allow an arbitrary number of spaces and tabs in addition to the number. Note that this will remove the whitespace along with the number. If you want to keep the whitespace, use

    /^([ \t]*)\d+([ \t]*)$/m
    

    And change your replacement string to

    $1yourReplacementString$2
    

    EDIT:

    I realize now that you don’t have line breaks, as in \r or \n or \r\n but <br> tags. That makes it a bit more difficult. Something like this should cover most cases:

    ~((?:^|<br[ ]*/?>)[ \t]*)\d+([ \t]*(?:$|<br\b))~
    

    Again, you need to add $1 and $2 around your replacement string to not remove the <br> tags.

    But as Andy said, HTML should not be dealt with using regular expressions. Either use the built-in DOM module provided by PHP, or some 3rd party library like this one.

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

Sidebar

Related Questions

I want to build a simple application with the MVVM pattern. This application will
I want to build a Cocoa application using the Model-View-Controller design pattern. I have
There is a Java library I want to use as part of my build,
I want to build a javascript function that maintains state. Here's a pattern that
I want to build pattern for preg_match that will match any string with length
I want to be able to replace specific pattern in .java files on build
I want to build a bunch of Perl subrotines that all have the same
Is there a publish/subscribe pattern in android? What I want to achieve is I
I want to build a shop in which the products have a little wizard
I want to build a windosform application using Repository and Unit of Work pattern.

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.