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

  • Home
  • SEARCH
  • 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 3394818
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:12:56+00:00 2026-05-18T04:12:56+00:00

I am trying to match <input> of type hidden fields using this pattern: /<input

  • 0

I am trying to match <input> of type hidden fields using this pattern:

/<input type="hidden" name="([^"]*?)" value="([^"]*?)" />/

This is some sample form data:

<input type="hidden" name="SaveRequired" value="False" /><input type="hidden" name="__VIEWSTATE1" value="1H4sIAAtzrkX7QfL5VEGj6nGi+nP" /><input type="hidden" name="__VIEWSTATE2" value="0351118MK" /><input type="hidden" name="__VIEWSTATE3" value="ZVVV91yjY" /><input type="hidden" name="__VIEWSTATE0" value="3" /><input type="hidden" name="__VIEWSTATE" value="" /><input type="hidden" name="__VIEWSTATE" value="" />

But I am not sure that the type, name, and value attributes will always appear in the same order. If the type attribute comes last, the match will fail because in my pattern it’s at the start.

Question:
How can I change my pattern so it will match regardless of the positions of the attributes in the <input> tag?

P.S.: By the way I am using the Adobe Air based RegEx Desktop Tool for testing regular expressions.

  • 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-18T04:12:56+00:00Added an answer on May 18, 2026 at 4:12 am

    Contrary to all the answers here, for what you’re trying to do regex is a perfectly valid solution. This is because you are NOT trying to match balanced tags– THAT would be impossible with regex! But you are only matching what’s in one tag, and that’s perfectly regular.

    Here’s the problem, though. You can’t do it with just one regex… you need to do one match to capture an <input> tag, then do further processing on that. Note that this will only work if none of the attribute values have a > character in them, so it’s not perfect, but it should suffice for sane inputs.

    Here’s some Perl (pseudo)code to show you what I mean:

    my $html = readLargeInputFile();
    
    my @input_tags = $html =~ m/
        (
            <input                      # Starts with "<input"
            (?=[^>]*?type="hidden")     # Use lookahead to make sure that type="hidden"
            [^>]+                       # Grab the rest of the tag...
            \/>                         # ...except for the />, which is grabbed here
        )/xgm;
    
    # Now each member of @input_tags is something like <input type="hidden" name="SaveRequired" value="False" />
    
    foreach my $input_tag (@input_tags)
    {
      my $hash_ref = {};
      # Now extract each of the fields one at a time.
    
      ($hash_ref->{"name"}) = $input_tag =~ /name="([^"]*)"/;
      ($hash_ref->{"value"}) = $input_tag =~ /value="([^"]*)"/;
    
      # Put $hash_ref in a list or something, or otherwise process it
    }
    

    The basic principle here is, don’t try to do too much with one regular expression. As you noticed, regular expressions enforce a certain amount of order. So what you need to do instead is to first match the CONTEXT of what you’re trying to extract, then do submatching on the data you want.

    EDIT: However, I will agree that in general, using an HTML parser is probably easier and better and you really should consider redesigning your code or re-examining your objectives. 🙂 But I had to post this answer as a counter to the knee-jerk reaction that parsing any subset of HTML is impossible: HTML and XML are both irregular when you consider the entire specification, but the specification of a tag is decently regular, certainly within the power of PCRE.

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

Sidebar

Related Questions

I'm trying to assign a variable from a html text input value and then
Lets say i have a piece of code like this: test pattern | pattern
I have an ASP.NET page and I am trying to quickly match the validation
I'm using Alloy's Complex Form Example found here . The example he provides is
Im am struggling with trying to figure out a selector for this kind of
I'm trying to write a pattern that composes two other patterns, but I'm not
I am trying to changed the innerHtml property of a label in a js
I'm trying to get one div to float left, and one div to float
I'm trying to build a search that is similar to that on Google (with
I am trying to set up a service similar to rubular , but with

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.