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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:25:30+00:00 2026-06-09T20:25:30+00:00

Ok, so I have a string $title_string which could look like any of the

  • 0

Ok, so I have a string $title_string which could look like any of the following:

$title_string = "20.08.12 First Test Event";
$title_string = "First Test event 20/08/12";
$title_string = "First Test 20.08.2012 Event";

I need to end up with two variables:

$title = "First Test Event";
$date = "20.08.12";

The formatting for the date should be converted to full-stops, regardless of what it was originally.

The Regex string that I started with looks something like this:

$regex = ".*(\d+\.\d+.\d+).*";

But I can’t get this to work in the way I need it to. So all in all, I need to locate a date in a string, remove it from the string and format it correctly. Cheers.

  • 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-09T20:25:31+00:00Added an answer on June 9, 2026 at 8:25 pm

    Matching dates with regular expressions can be quite complex. See this question for an example regex. Once you’ve found the date, you can remove it from the title using str_replace().

    Here’s a basic implementation:

    $title_string = "20.08.12 First Test Event";
    
    if ( preg_match('@(?:\s+|^)((\d{1,2})([./])(\d{1,2})\3(\d{2}|\d{4}))(?:\s+|$)@', $title_string, $matches) ) {
        //Convert 2-digits years to 4-digit years.
        $year = intval($matches[5]);
        if ($year < 30) { //Arbitrary cutoff = 2030.
            $year = 2000 + $year;
        } else if ($year < 100) {
            $year = 1900 + $year;
        }
    
        $date = $matches[2] . '.' . $matches[4] . '.' . $year;
        $title = trim(str_replace($matches[0], ' ', $title_string));
        echo $title_string, ' => ', $title, ', ', $date;
    } else {
        echo "Failed to parse the title.";
    }
    

    Output:

    20.08.12 First Test Event => First Test Event, 20.08.2012
    
    • 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 looks like: <html><head><title>example</title></head><body>some example text</body></html> I get this string
I have bunch of strings, some of which are fairly long, like so: movie.titles
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull
i have a string like this one $sitesinfo = 'site 1 titles-example1.com/ site 2
Here's my situation.. Suppose you have the following model entities, which represent single tables
I have a string which can include none, one or two values. In case
I have a ViewModel that looks like this: public class CreateReviewViewModel { public string
Suppose I have two lists of type MyCustomType , a class which could be
I have two entities one is Event and another is User. User can like
I have the following string: <h1 class=title>This is some heading?</h1><h2 class=desc>Here is the description

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.