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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:42:50+00:00 2026-05-26T12:42:50+00:00

I have a string that can be very long and contain various lines and

  • 0

I have a string that can be very long and contain various lines and characters.

I am wanting to extract all lines that are surrounded by SB & EB:

SB1EB
SBa description of various lengthEB
SB123.456.78EB
SB99.99EB
SB99.99EB
SB2EB
SBanother description of various lengthEB
SB123.456.00EB
SB199.99EB
SB199.99EB
3
another description of various length that I don't want to return
123.456.00
599.99
599.99
SB60EB
SBanother description of various length that i want to keepEB
SB500.256.10EB
SB0.99EB
SB0.99EB
another bit of text that i don't want - can span multiple lines

This is the pattern I am using in PHP:

preg_match_all('/SB(\d+)EB\nSB(\w.*)EB\nSB(\d{3}\.\d{3}\.\d{2})EB\nSB(\d.*)EB\nSB(\d.*)EB\n/', $string, $matches)

So this should hopefully return:

[0] -> SB1EB
SBa description of various lengthEB
SB123.456.78EB
SB99.99EB
SB99.99EB

[1] -> SB2EB
SBanother description of various lengthEB
SB123.456.00EB
SB199.99EB
SB199.99EB

[2] -> SB60EB
SBanother description of various length that i want to keepEB
SB500.256.10EB
SB0.99EB
SB0.99EB

But I’m obviously doing something wrong because it isn’t matching anything. Can somebody help please?

SOLUTION:

Based on @Sajid reply:

if (preg_match_all('/(?:SB.+?EB(?:[\r\n]+|$))/', $string, $result)) {

    for($i=0;$i<count($result[0]);$i++){

        $single_item = $result[0][$i];
        $single_item = str_replace("SB","",$single_item);
        $single_item = str_replace("EB","",$single_item);
        if (preg_match('/(\d{3}\.\d{3}\.\d{2})/', $single_item)) {

            $id = $single_item;
            $qty = $result[0][$i-2];
            $name = $result[0][$i-1];
            $price = $result[0][$i+1];
            $total = $result[0][$i+2];

        }

    }

}

It’s a bit messy, but it works! 🙂

Thanks

  • 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-26T12:42:50+00:00Added an answer on May 26, 2026 at 12:42 pm

    Based on @Sajid reply:

    if (preg_match_all('/(?:SB.+?EB(?:[\r\n]+|$))/', $string, $result))
    {
        for ($i=0; $i<count($result[0]); $i++)
        {
            $single_item = $result[0][$i];
            $single_item = str_replace("SB","",$single_item);
            $single_item = str_replace("EB","",$single_item);
            if (preg_match('/(\d{3}\.\d{3}\.\d{2})/', $single_item))
            {
                $id = $single_item;
                $qty = $result[0][$i-2];
                $name = $result[0][$i-1];
                $price = $result[0][$i+1];
                $total = $result[0][$i+2];
            }
        }
    }
    

    It’s a bit messy, but it works! 🙂

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

Sidebar

Related Questions

I have a String which can be very long so I want to split
I have a text file that contains very long lines. I need one piece
I have javascript string variable with var sttr=We prefer questions that can be answered
I have an object that can build itself from an XML string, and write
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
I have a C# collection of strings. Each string is a sentence that can
I have a method that will receive a string , but before I can
I have a variable that can either contain a list of strings or a
I have a textbox to display a very long Base64 string. The TextBox.Multline =
I have a C# Windows Service. The OnStart() method contains 3 lines that all

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.