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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:16:41+00:00 2026-05-20T21:16:41+00:00

I hate regular expressions, but for what I am doing I’m sure there is

  • 0

I hate regular expressions, but for what I am doing I’m sure there is no other simpler option.
Anyway I have been working with this experssion:

/(([a-zA-z_]+)[\.]?+)+/

To try and match something similar to this

"text.lol".something.another etc..

And with preg_match return an array similar to

Array
(
    [0] => "text.lol"
    [1] => something
    [2] => another
)

But instead all I am getting is the first matched item twice in the array?

Can anyone help?

  • 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-20T21:16:42+00:00Added an answer on May 20, 2026 at 9:16 pm

    This gives the output you want for the input you specified:

    $s = '"text.lol".something.another';
    preg_match_all('/"[^"]+"|[^.]+/', $s, $m);
    $values = $m[0];
    print_r($values);
    

    Here’s a full implementation that allows escaped quotes:

    function encode($original) {
        foreach ($original as &$s) {
            $s = addslashes($s);
            if (strpos($s, '.') !== false) $s = '"'.$s.'"';
        }
        return join('.', $original);
    }
    
    function decode($s) {
        // These regular expressions courtesy of ridgerunner:
        preg_match_all('/"([^"\\\\]*+(?:\\\\.[^"\\\\]*)*)"|([^.]+)/', $s, $m);
        // This one has poorer performance, but is easier to read:
        // preg_match_all('/"((?:\\\\.|[^"\\\\])+)"|([^.]+)/', $s, $m);
        $values = array();
        foreach ($m[1] as $k => $v) $values[] = stripslashes($v? $v : $m[2][$k]);
        return $values;
    }
    
    $test_cases = array('a.b', 'a\\', '.a\\', 'a.b"c', '"a');
    $encoded = encode($test_cases);
    $decoded = decode($encoded);
    
    echo '<pre>Encoded: '.$encoded."\n";
    echo print_r($decoded, 1).'</pre>';
    

    Output:

    Encoded: "a.b".a\\.".a\\"."a.b\"c".\"a
    Array
    (
        [0] => a.b
        [1] => a\
        [2] => .a\
        [3] => a.b"c
        [4] => "a
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hate to have to ask, but I'm pretty stuck here. I need to
There's been a cluster of Perl-hate on Stack Overflow lately, so I thought I'd
I have been thinking about a regular expression that can transform a list like
I hate code that looks like its been hacked together. I have just written
I hate regular expressions and I was hoping someone could help with a regualar
Hate to ask others to do my research for me, but perhaps there's a
I hate case sensitivity in databases, but I'm developing for a client who uses
I hate Physics, but I love software development. When I go back to school
For example, I hate typing things like: $x = mysql_escape_string(stripslashes($_GET['x'])); Is there a way
I have a small to medium project that is in C++/CLI. I really hate

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.