Issue with Regular Expression
<p>I made an application in which I can get a field's value through a regular expression with the help of a matcher... I made a method in which I pass a field and get a response. In string today I got some odd behaviour in my response I got AgentId = 25001220052805950 and after matcher I got <code>fake</code> so I have to check whether a field whose name contains "AgentId" exists and verify the values. </p>

<p><strong>Needed Fields:</strong>
 <code>SecondaryAgentId=fake;</code> <code>PrimaryAgentId=fake;</code> </p>

<p><strong>Responce :</strong></p>

<pre><code>IsPrimaryAgentId=true; AgentId=25001220052805950; MerchantID=19; Cashier=michael; IsManualPayment=1; UserID=GraceRose; Password=rose1234; AmountUserEntered=2; AmountApproved=0; AmountDifference=0; Amount=0; CustomerNameAttempts=0; ProductID=Agriculture; InvoiceID=inv7443; SiteUrl=http://www.thcelink.com/index.php/shoping/checkout/step/step-1; ReturnURL=http://220.2.3:2027/Customer/Thanks.aspx; ResponseType=1; PrimaryAgentId=fake; PrimaryCurrencyCode=fake; SecondaryAgentId=fake; SecondaryCurrencyCode=fake; MerchantName=GraceRose; EmailId=rr@myglobal.com; Query1Attempts=0; MerchantTransactionID=543; MerchantTransactionSequenceID=246; txtAmtIsVisible=false; isQuery1Executed=false; isQuery2Executed=false; Voucher=fake; Passcode=fake; Error=fake; QueryType=fake; Payer=fake; CurrencyName=fake; CurrencySymbol=fake; CustomerName=fake; EmailBody=fake; ErrorText=fake; CustomerEmailID=fake; NavigatePageValue=0; IsCustomerInsertSucess=false; IdType=fake; IdNumber=fake; AggregateAttempts=0; Voucher2=fake; PassCode2=fake; Voucher3=fake; PassCode3=fake; TransCode=0; TransactionDate=2012-06-11T12:04:52.921875+05:30; NumberInWords=fake; MerchantCompany=fake; InvoiceNumber=fake; OverPaidAmount=0; InsufficientAmount=0; OverPaymentForEmail=fake; RedirectPage=false; 
</code></pre>

<p><strong>Update::</strong></p>

<pre><code>private String GetString1(String strManualproResponce2, String paternField) {
        // TODO Auto-generated method stub
        String s = null;
        if(paternField.equalsIgnoreCase("AgentId"))
        {
            Pattern pinPattern2 = Pattern.compile("^"+paternField + "=(.*?);");
            ArrayList&lt;String&gt; pins2 = new ArrayList&lt;String&gt;();
            Matcher m2 = pinPattern2.matcher(strManualproResponce2);
            while (m2.find()) {
                pins2.add(m2.group(1));
                s = m2.group(1);
            }
        }else
        {
        Pattern pinPattern2 = Pattern.compile(paternField + "=(.*?);");
        ArrayList&lt;String&gt; pins2 = new ArrayList&lt;String&gt;();
        Matcher m2 = pinPattern2.matcher(strManualproResponce2);
        while (m2.find()) {
            pins2.add(m2.group(1));
            s = m2.group(1);
        }
        }

        return s;
    }
</code></pre>
