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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:38:21+00:00 2026-05-12T21:38:21+00:00

I want to check posted content against a pattern. I am having trouble setting

  • 0

I want to check posted content against a pattern. I am having trouble setting up this preg_match (or array?). The pattern being…

TEXTHERE:TEXTHERE
TEST:TEST
FILE:FILE

AND

TEXTHERE:TEXTHERE TEST:TEST FILE:FILE

I want to check for either pattern, the one with the whitespace and the one with the line break. If the posted content is this… (with extra line breaks and/or whitespace)

TEXTHERE:TEXTHERE

TEST:TEST

FILE:FILE

I want it to somehow display as…

TEXTHERE:TEXTHERE
TEST:TEST
FILE:FILE

and still match against the pattern.

I want it to still work, somehow by stripping the extra line break/and or extra white space…

$loader = file_get_contents( 'temp/load-'.$list.'.php' );

If it doesn’t follow the string pattern, I want it to output an error message, etc.

if($loader == ???) { // done
} else { // error
}
  • 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-12T21:38:21+00:00Added an answer on May 12, 2026 at 9:38 pm

    Try something like this:

    $loader = 'TEXTHERE:TEXTHERE
    
    TEST:TEST
    
    FILE:FILE';
    
    if(preg_match('/^[A-Z]+:[A-Z]+(\s+[A-Z]+:[A-Z]+)*$/', $loader)) {
        echo preg_replace('/\s{2,}/', "\n", $loader);
    }
    

    Output:

    TEXTHERE:TEXTHERE 
    TEST:TEST
    FILE:FILE
    

    You’ll get the same output for:

    $loader = 'TEXTHERE:TEXTHERE        TEST:TEST          FILE:FILE';
    

    You first check if it matches:

    [A-Z]+:[A-Z]+    # match a word followed by a colon followed by a word
    (                # open group 1
      \s+            #   match one or more white space chars (includes line breaks!)
      [A-Z]+:[A-Z]+  #   match a word followed by a colon followed by a word
    )*               # close group 1 and repeat it zero or more times
    

    And if it matches the above, you replace 2 or more successive white space chars \s{2,} with a single line break.

    Of course, you may need to adjust [A-Z]+ to something else.

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

Sidebar

Related Questions

I want to check in zend, whether a posted form value 'name' contains a
This question is related to another one I've posted recently: Check printing with Java/JSP
I don't want check if an item with a value exists in the arraylist,
I want to check whether a string is a file name (name DOT ext)
I want to check the integrity of a backup of a Ubuntu disk, copied
I want to check to see if an XML document contains a 'person' element
I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table
I want to check if a particular page gets redirected or not. However, whenever
I want to check a particular website from various locations. For example, I see
I want to check the type of an Object. How can I do that?

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.