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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:56:13+00:00 2026-06-17T14:56:13+00:00

hello need help in regex i use this to split strings with capital letters

  • 0

hello need help in regex i use this to split strings with capital letters like OldMcDonald
preg_split('/(?=[A-Z])/', $data, -1, PREG_SPLIT_NO_EMPTY);

output 
[0] => Old 
[1] => Mc 
[2] => Donald 

now i need to split strings like MWTTH
i need to tell the regex that a T with a letter H is one word how can i apply in my regex?

need the output: 
[0] => M 
[1] => w 
[2] => T 
[3] => TH

when i tried

$array = preg_split('/(?=[A-Z][TH])/', $data, -1, PREG_SPLIT_NO_EMPTY);

Output is

Array
(
    [0] => MTW
    [1] => F
    [2] => TH
)  

MTH Does not break appart, No time to study regex now.

  • 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-17T14:56:14+00:00Added an answer on June 17, 2026 at 2:56 pm

    I should have studied a little further i could have got it, anyway i already found it out i used:

    $data = 'MTWFTH';
    $array = preg_split('/(?=TH|M|T|W|F|S)/', $data, -1, PREG_SPLIT_NO_EMPTY);
    

    OUTPUT

    array (size=5)
      0 => string 'M' (length=1)
      1 => string 'T' (length=1)
      2 => string 'W' (length=1)
      3 => string 'F' (length=1)
      4 => string 'TH' (length=2)
    

    while this will only work for predefined data like mine.

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

Sidebar

Related Questions

Hello i am in desperate need of help on this i have an image
I'm at a loss, I need some help. The string looks like: Hello World
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
I need help to do this regex. The sentence can't be less than 4
Hello I need some help understanding what is going on in this assembly code:
I have a string that looks like this: the word you need is 'hello'
Hello stack overflow I need help with this problem. Ok, I have a flat
I need help to solve this problem: I have a csv file like this
Hello everyone, I need help on creating a button like in the above picture.
Hello I need help with displaying data from 2 table. So i Have 2

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.