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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:07:58+00:00 2026-06-06T08:07:58+00:00

Let’s say for an instance I have this string: var a=23434,bc=3434,erd=5656,ddfeto=’dsf3df34dff3′,eof=’sdfwerwer34′,wer=4554; How should I

  • 0

Let’s say for an instance I have this string:

var a=23434,bc=3434,erd=5656,ddfeto='dsf3df34dff3',eof='sdfwerwer34',wer=4554;

How should I match all the initializations assigned as integer? Here’s my current try, but I don’t understand why it’s matching everything.

$pattern = '/var (.*=\d)/';
preg_match_all($pattern,$page,$matches);

EDIT: I’m trying to match each initialization:

1 => a=23434
2 => bc=3434

and so on…

EDIT: Here’s an update on my try:

$pattern = '/[^v^a^r] (.*=\d+),/';
preg_match_all($pattern,$page,$matches);

0 => 'var a=23434,bc=3434,erd=5656,'
1 => 'a=23434,bc=3434,erd=5656'
  • 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-06T08:08:01+00:00Added an answer on June 6, 2026 at 8:08 am

    The function is using “greedy” matching. You don’t want that. In PHP, you can either follow your wildcard with a ? to specify non-greedy matching, as in:

    $pattern = '/var (.*?=\d)/';
    

    or using the U flag as documented here, as in:

    $pattern = '/var (.*=\d)/U';
    

    which will make all wildcards use non-greedy matching.

    EDIT: Also, since you’re including “var”, you would probably need to change it to

    $pattern = '/var (.*?=\d)*/';
    

    or

    $pattern = '/var (.*=\d)*/U';
    

    to match any number of (.*=\d) patterns.


    EDIT: Update per discussion:

    PHP

    $page = "var a=23434,bc=3434,erd=5656,ddfeto='dsf3df34dff3',eof='sdfwerwer34',wer=4554;";
    $pattern = '/([a-zA-Z]+=\d+)/';
    
    preg_match_all($pattern,$page,$matches);
    
    
    print_r($matches[1]);
    

    Produces

    Array
    (
        [0] => a=23434
        [1] => bc=3434
        [2] => erd=5656
        [3] => wer=4554
    )
    

    Note: This filters out the entries that have the RHS enclosed in single quotes. If you don’t want that, let us know.


    EDIT #2: My answer to your question exceeded the size of the comment box so I edited my answer.

    The [a-zA-z] expression matches only alphabetical characters of either case. Note that the updated code also removed the “ungreedy” modifier, so we actually want it to be greedy now. And since we want it to be greedy, the . will “eat” too much. Go ahead, play around with the code, see what happens when you change it to .* it is a good opportunity to get more familiar with regex.

    Since the . “eats” too much, we need to restrict it from matching all characters to matching the ones we want. We could have used something like

    $pattern = '/([^\s,]*=\d+)/';
    

    where the [^\s,]* would match any number of non-whitespace, non-comma characters. This would also have worked for your test cases.

    But in this case, we can say confidently what the characters we want to include are, so instead of “blacklisting” characters, we’ll “whitelist” them. In this case we specify that we want to match any alphabetical character of either case.

    As is the case with many things, especially in programming, there are many ways to skin a cat. There are a number of alternative regex patterns that would have also worked for your test cases. Its up to you to understand the limits of each, how they will perform on edge cases, and how maintainable they are, and make a decision.

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

Sidebar

Related Questions

Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let’s say I have a number like 0x448 . In binary this is 0100
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have the following classes : public class MyProductCode { private String
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have table with column 'URL' whrere I store urls like this

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.