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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:04:44+00:00 2026-05-14T04:04:44+00:00

$regexp = ‘/(?:<input\stype=hidden\sname=){1}([a-zA-Z0-9]*)(?:\svalue=1\s\/>)/’; $response = ‘<input type=hidden name=7d37dddd0eb2c85b8d394ef36b35f54f value=1 />’; preg_match($regexp, $response, $matches); echo

  • 0
$regexp = '/(?:<input\stype="hidden"\sname="){1}([a-zA-Z0-9]*)(?:"\svalue="1"\s\/>)/';
$response = '<input type="hidden" name="7d37dddd0eb2c85b8d394ef36b35f54f" value="1" />';
preg_match($regexp, $response, $matches);

echo $matches[1]; // Outputs: 7d37dddd0eb2c85b8d394ef36b35f54f

So I’m using this regular expression to search for an authentication token on a webpage implementing Joomla in order to preform a scripted login.

I’ve got all this working but am wondering what is wrong with my regular expression as it always returns 2 items.

Array ( [0] => [1] => 7d37dddd0eb2c85b8d394ef36b35f54f)

Also the name of the input I’m checking for changes every page load both in length and name.

  • 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-14T04:04:45+00:00Added an answer on May 14, 2026 at 4:04 am

    Nothing is wrong. Item [0] always contains the entire match. From the docs (emphasis mine):

    If matches is provided, then it is
    filled with the results of search.
    $matches[0] will contain the text that
    matched the full pattern
    , $matches[1]
    will have the text that matched the
    first captured parenthesized
    subpattern, and so on.

    Your regex (overlooking the fact that you are working on HTML with regexes in the first place, which you know you shouldn’t) is a bit too complicated.

    $regexp = '#<input\s+type="hidden"\s+name="([0-9a-f]*)"\s+value="1"\s*/>#i'
    
    • You don’t need the non-capturing groups at all.
    • You use \s, which limits you to a single character. \s+ is probably better.
    • Using something different than / as the regex boundary makes escaping of forward slashes in the regex unnecessary.
    • Making the regex case-insensitive could be useful, too.
    • The auth token looks like a hex string, so matching a-z is unnecessary.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php regexp: remove all attributes from an html tag $input = '<div
I have this RegExp this.value = this.value.replace(/(^((?!(\n|[0-9])).)*$)/mg,''); That replaces everything except digits and new
Looking for a regexp sequence of matches and replaces (preferably PHP but doesn't matter)
I have a regexp which checks if a value has at least 10 digits:
I'm using a RegExp to validate some user input on an ASP.NET web page.
regexp: var s = document.getElementById(username).value; if s == \ \ \ \; var result
The following regexp matches the trailing 's' on a word or word fragment: /s\b/i
I need a simple regexp for php preg_replace: Input: Quick brown :no: fox etc
How to set the regExp value in the dijit.form.ValidationTextBox to only allow Letters, Lines
I need a ruby regexp pattern that matches a string containing a letter (for

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.