views:

583

answers:

2
preg_match('/(.*?)see below[^,\.<]*/s',$xml,$match);
echo $match[0];

the ouput is,which I think the non-greedy matching is not working:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
        <soap:Header>
            <UserCredentials xmlns="http://jobg8.com/postadvertheaders"&gt;
                <Username>******</Username>
                <Password>******</Password>
            </UserCredentials>
        </soap:Header>
        <soap:Body>
            <PostAdvert xsi:noNamespaceSchemaLocation="PostAdvertSchema.xsd" xmlns="http://jobg8.com/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            <Adverts AccountNumber="" xmlns="http://jobg8.com/"&gt;
            <PostAdvert>
                <JobReference>JS310969/657368</JobReference>
                <ClientReference>JS310969</ClientReference>
                <Classification>Accounting</Classification>
                <SubClassification>Other</SubClassification>
                <Position>Risk Management Contract Analyst</Position>
                <Description>
                    <![CDATA[<P>Proficiently and accurately complete all department functions as assigned. Maintain internal/external client relationships, as well as intradepartmental relationships. Analyze data to determine departmental and global risk assessment, with the authority to carry out risk mitigation solutions. Analyze Purchase, Servicing and Pooling & Servicing Agreements to determine departmental and global risk assessments, with the authority to carry out risk mitigation solutions. Research administrative laws, regulations and industry guidance. Review vendor agreements to confirm such agreement contain standard terms and conditions. Develop contractual controls identified from risk assessments. Coordinate special projects. Lead department/ad hoc meetings to communicate issues, changes, and company business. Work directly with Risk Management managers and Executives to manage and implement department initiatives. <BR>
                    <BR>The Contract Analyst will assist in the mitigation of loss to the company through the prompt and accurate dissemination of information, including, without limitation, information associated with Wilshire contract review, escalated response review and interaction with internal and external clients, while ensuring Wilshire meets its contractual and servicing obligations. Concurrently, this individual will work with the various Risk Management departments to support new initiatives.<BR>
                    <BR>Effective project management skills. Ability to supervise staff. Critical thinking skills. <BR>
                    <BR>COMMUNICATION SKILLS:<BR>Effectively and professionally communicate with internal and external customers, vendors, and other third parties in a timely manner. Effectively and professionally identify, handle and resolve recurring problems in a tactful manner. Effectively motivate, coach and train<BR>Effectively manage meetings. <BR>
                    <BR>TECHNICAL SKILLS: <BR>Microsoft Excel, Access and SQL<BR>
                    <BR>Manpower is an Equal Opportunity Employer (EOE/AA).</P>]]>
                </Description>
                <Location>Oregon</Location>
                <Area>Not Specified</Area>
                <PostCode>97005</PostCode>
                <Country>United States</Country>
                <EmploymentType>Contract</EmploymentType>
                <StartDate>ASAP</StartDate>
                <WorkHours>Not Specified</WorkHours>
                <VisaRequired>Applicants must be eligible to work in the specified location</VisaRequired>
                <PayPeriod>Hourly</PayPeriod>
                <PayMinimum>23</PayMinimum>
                <PayMaximum>26</PayMaximum>
                <Currency>US Dollar . USD</Currency>
                <Contact>Manpower</Contact>
                <JobDetailsURL>http://www.jobg8.com/JobG8SearchFullView.aspx?aid=JOBG8&amp;jbid=158&amp;jid=657368&lt;/JobDetailsURL&gt;
                <ApplicationURL>http://www.jobg8.com/Application.aspx?FGissiUpsXxXA%2fvYzNruPwk&lt;/ApplicationURL&gt;
                <JobSource>JobServe USA</JobSource>
                <AdvertiserName>Manpower - CORP</AdvertiserName>
                <ActivationDate>12/05/2009 23:40:56</ActivationDate>
                <ExpiryDate>09/06/2009 23:40:56</ExpiryDate>
            </PostAdvert>
            <PostAdvert>
                <JobReference>JS2401898/JAVA-DEV/657366</JobReference>
                <ClientReference>JS2401898/JAVA-DEV</ClientReference>
                <Classification>I.T. & Communications</Classification>
                <SubClassification>Analyst Programmer</SubClassification>
                <Position>Sr. Java Developer - JAVA-DEV</Position>
                <Description>
                    <![CDATA[Immediate 3 months contract with one of our active clients in Atlanta, GA.<BR>
                    <BR>Job Duties: This candidate will be working on a development project called American Recovery and Reinvestment Act - ARRA and will be helping to finish the development of a Java Web application utilizing a service oriented approach, ensuring a testing strategy while maintaining a good security posture. The technology stack will consist of utilizing Struts2, Spring/Hibernate with Web services on JBOSS. <BR>
                    <BR>Candidate Profile:<BR> We are looking for a seasoned Java Developer who has at least 4 to 5 years Java programming experience in a Web environment. <BR>The candidate must be able to communicate ideas and work status clearly. <BR>The candidate must have at least 5 years Java with at least 2 years programming SOA type applications and have a good working knowledge of all the underlying technologies associated with this architecture. <BR>This candidate will be self motivated while ensuring results. <BR>
                    <BR>We would prefer someone who is knowledgeable about deploying and managing Web service on JBOSS. <BR>
                    <BR>
                    <BR>Skills needs are: GUI Technologies: HTML, Javascript, JSP, Servlets, AJAX, DWR, JSTL Framework: Struts2, Struts, Spring, Hibernate, Web Services (SOA) Other: Maven, Junit (testing),<BR>
                    <BR>Subversion Application Containers: Apache/Tomcat, JBOSS and Jasper Reports.<BR>XBRL knowledge and implementation experience will be a plus.<BR> <P>Required Skills: <BR>Java, Strust2, JBOSS, XBRL, Jasper Reports]]>
                </Description>
                <Location>Georgia</Location>
                <Area>Atlanta</Area>
                <PostCode>30332</PostCode>
                <Country>United States</Country>
                <EmploymentType>Contract</EmploymentType>
                <Duration>3 months</Duration>
                <WorkHours>Not Specified</WorkHours>
                <VisaRequired>Applicants must be eligible to work in the specified location</VisaRequired>
                <PayPeriod>Annual</PayPeriod>
                <Currency>US Dollar . USD</Currency>
                <Contact>Aesha Jadhav</Contact>
                <JobDetailsURL>http://www.jobg8.com/JobG8SearchFullView.aspx?aid=JOBG8&amp;jbid=158&amp;jid=657366&lt;/JobDetailsURL&gt;
                <ApplicationURL>http://www.jobg8.com/Application.aspx?TaJERQNjwYgjsX
                8AjoEoPgi</ApplicationURL>
                <JobSource>JobServe USA</JobSource>
                <AdvertiserName>ESG Consulting</AdvertiserName>
                <ActivationDate>12/05/2009 23:21:03</ActivationDate>
                <ExpiryDate>09/06/2009 23:21:02</ExpiryDate>
            </PostAdvert>
            <PostAdvert>
                <JobReference>JS2189216/TPD/620184</JobReference>
                <ClientReference>JS2189216/TPD</ClientReference>
                <Classification>Accounting</Classification>
                <SubClassification>Other</SubClassification>
                <Position>Trading Platform Developer - TPD</Position>
                <Description>
                <![CDATA[<P>
                <STRONG>PCR</STRONG> is working with one of our retained clients to identify candidates for a role as the <STRONG>Developer </STRONG>to join a team developing <STRONG>a </STRONG>proprietary Real Time trading platform. Potential candidates should have at least 5 years of hands-on development experience in C#/C working with real-time, high volume trading systems. S<STRONG>pecific experience with OMS/EMS, Execution/FIX and Market Date components will be key. Developing and integrating these components into the existing GUI interface will also be a focus.</STRONG> Selected candidates will develop, tune and support the platform focusing on building a system that maximizes efficiency, speed and capacity. <BR> <BR>This role is a full time, direct hire position located in <STRONG>Charlotte, NC</STRONG>. Attractive compensation, benefits and bonus structure are available. This privately held international firm is establishing a significant presence in the Charlotte area. They are committed to excellence of execution and have quickly become an industry leader.<BR> <BR>Qualified candidates should send their complete resume and compensation requirements to Jim Scialabba, Sales Recruiting Manger of PCR, Inc. via email at . <BR> <BR>
                <STRONG>3rd party candidates will not be accepted</STRONG>.</P>
                <BR>
                <P>
                <STRONG>Requirements:</STRONG>
                <BR>
                </P>
                <BR>
                <UL>
                <BR>
                <LI>8 Years overall development experience in C#/C working with real-time, high volume trading systems <BR>Bachelor's Degree in Computer Science or Mathematics discipline (Master's or above preferred) <BR>5 Years Object Oriented development methodology experience <BR>5 Years experience working on the development of trading platforms<BR>
                <LI>Previous experience with multi-threading, trading system API's, ECN Connectivity and TIBCO <BR>Integrate custom systems with trading exchanges and market data vendors <BR>Excellent communication and documentation skills <BR>Strong interest in the financial markets and the business processes that are involved in information technology components that allow for Real Time trading <BR>Eligible to work for any employer to in the United States </LI>
                </UL>]]>
                </Description>
                <Location>North Carolina</Location>
                <Area>Charlotte</Area>
                <PostCode>28203</PostCode>
                <Country>United States</Country>
                <EmploymentType>Permanent</EmploymentType>
                <WorkHours>Not Specified</WorkHours>
                <VisaRequired>Applicants must be eligible to work in the specified location</VisaRequired>
                <PayPeriod>Annual</PayPeriod>
                <PayMinimum>75000</PayMinimum>
                <PayMaximum>100000</PayMaximum>
                <Currency>US Dollar . USD</Currency>
                <PayAdditional>excellent benefits and bonus structure</PayAdditional>
                <Contact>Jim Scialabba</Contact>
                <JobDetailsURL>http://www.jobg8.com/JobG8SearchFullView.aspx?aid=JOBG8&amp;jbid=158&amp;jid=620184&lt;/JobDetailsURL&gt;
                <ApplicationURL>http://www.jobg8.com/Application.aspx?1M4Nk%2bPwXoof6ZrDGtaezAg&lt;/ApplicationURL&gt;
                <JobSource>JobServe USA</JobSource>
                <AdvertiserName>Professional Computer Resources, Inc.</AdvertiserName>
                <ActivationDate>22/04/2009 14:17:53</ActivationDate>
                <ExpiryDate>20/05/2009 14:17:53</ExpiryDate>
            </PostAdvert>
            <PostAdvert>
                <JobReference>JS2305199/TSD/620185</JobReference>
                <ClientReference>JS2305199/TSD</ClientReference>
                <Classification>Accounting</Classification>
                <SubClassification>Other</SubClassification>
                <Position>Trading Systems Developer - TSD</Position>
                <Description>
                    <![CDATA[<P>
                    <STRONG>
                    <U>Trading System Developer<BR>
                    </U>
                    </STRONG>
                    <STRONG>PCR</STRONG> is working with one of our retained clients to identify candidates for development roles joining a team building and maintaining a proprietary <STRONG>Real Time trading platform</STRONG>. Potential Trading System Developer candidates should have at least eight years of hands-on development experience in C#/C working with <STRONG>Real Time, high volume trading systems</STRONG>. Previous experience developing multi-threaded trading systems. <STRONG>Specific experience with FIX orderflow and/or Market Data protocols will be key. Messaging Middleware such as TIBCO EMS, JMS, MSMQ or some other equivalent will also be a focus. </STRONG>The selected candidate will develop, tune and support the platform; constructing a system that maximizes efficiency, speed and capacity.</P>
                    <P>This role is a full time, direct hire position located in Charlotte, NC. Attractive compensation, benefits and bonus structure are available. This role may evolve into further management level capabilities as the department evolves. This privately held international firm is establishing a significant presence in the Charlotte area. They are committed to excellence of execution and have quickly become an industry leader.</P>
                    <P>Qualified Trading System Developer candidates should send their complete Resume and compensation requirements to Jim Scialabba, Sales Recruiting Manager of PCR, Inc. via email at (see below)

The above script is just for testing from which I expected the output to be just "see below)", that's why I used a non-greedy pattern to match the prefix.

Can anyone point out what I'm doing incorrectly?

+2  A: 

There are more problems here. (.?) means (a grouped) zero or one any character. This is what you want to get? Otherwise, the first item in the result array of preg_match always returns the expression that was matched against the pattern.

There are a lot of regex tools out there help you understand what's going on behind the scenes.

Török Gábor
Could you tell me why .*? didn't match nothing?This is what I did that test for.
Shore
+6  A: 

It looks like you are trying to use a regex on XML, regexes are fundamentally bad at parsing XML (see Can you provide some examples of why it is hard to parse XML and HTML with a regex? for why). What you need is an XML parser.

Chas. Owens
no,xml is also composed of characters,so I think it should also work.
Shore
@Shore: You haven't read the link. Regexes are simply *not* the right tool for reliably parsing general XML (a FSM cannot handle recursive structures). Also, there are many changes possible to the formatting of the XML which will not change its content but could cause an existing regex to fail.
ephemient
But I've used regex to parse xml and html for a long time,until today ...it's something to do with both greedy and non-greedy exist.
Shore
@Shore Then you have written bad, fragile code before today. Take the half hour it takes to learn to use a parser and save yourself a ton of trouble. Regexes are wonderful tools, but you have been driving nails into wood with a screwdriver. Learn to use a hammer.
Chas. Owens
maybe this sample can explain what I'm seeking for a solution better:$str = 'bcs see below!';preg_match('/(.*?)see below[^,\.<]*/s',$str,$match);echo $match[0];exit();the result is the entire string,but in fact I only want "see below!"
Shore
This is one of the questions that are "If you have to ask, you're doing it wrong."
Brad Gilbert