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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:44:30+00:00 2026-05-31T15:44:30+00:00

I’m still learning PHP regular expressions (and regular expressions in general), and would like

  • 0

I’m still learning PHP regular expressions (and regular expressions in general), and would like to ask for some help in returning a match from a non-greedy match on filler (I am working on an open-source CalDav client called Calico, that should be released to the community soon).

I used http://txt2re.com to generate this regular expression, and I am having trouble understanding how to retrieve whatever ‘$re4=’.*?’; # Non-greedy match on filler’ manages to catch. Could someone please help me?

$txt='BEGIN:VCALENDAR PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:America/New_York X-LIC-LOCATION:America/New_York BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:19700308T020000 RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:19701101T020000 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11 END:STANDARD END:VTIMEZONE BEGIN:VEVENT CREATED:20111219T194407Z LAST-MODIFIED:20091219T197731Z DTSTAMP:20111219T194431Z UID:c9bfc6b0-064e-4316-83fe-753db34e67ee SUMMARY:New Test DTSTART;TZID=America/New_York:20111219T150000 DTEND;TZID=America/New_York:20111219T160000 LOCATION:Philadelphia DESCRIPTION:Propfind test. END:VEVENT END:VCALENDAR ';

$re1='.*?'; # Non-greedy match on filler
$re2='(TZID)';  # Word 1
$re3='(:)'; # Any Single Character 1
$re4='.*?'; # Non-greedy match on filler
$re5='( )'; # Any Single Character 2

if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5."/is", $txt, $matches))
{
    $test = $matches[0][0];
    $word1=$matches[1][0];
    $c1=$matches[2][0];
    $c2=$matches[3][0];
    print "($test) ($word1) ($c1) ($c2) \n";
}

The text I am interested in is ‘TZID:America/New_York’, of which the ‘America/New_York’ portion I am trying to grab. Since the TZID can ultimately be anything (possibility of non-standard timezones), I am just trying to grab everything from the colon to the whitespace.

  • 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-31T15:44:31+00:00Added an answer on May 31, 2026 at 3:44 pm

    You don’t have the $re4 part wrapped in capturing parentheses so the match won’t actually be getting saved in to $matches.

    If you change it to $re4='(.*?)'; then $matches[3][0] will contain ‘America/New_York’


    If you’re just trying to capture the timezone you could use a simpler pattern:

    if (preg_match("/TZID:(.+?) /is", $txt, $matches))
    {
        print $matches[1];
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.