Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Apr 1

Written by: Steve Gray
4/1/2011 9:52 AM  RssIcon

The most straightforward way to match something, but only if it occurs within something else, is to use two regular expressions.

Use the first regex to match the blocks of text that contain what you're looking for. Use the second regex to search within the text matched by the first regex to find what you're looking for.


Suppose you want to match <p> tags and their contents, but only if they occur within a <div> tag. Other <p> tags should be skipped. You can easily match the <div> tags and their contents with

<div>.*?</div>

You can just as easily match the <p> tags with

<p>.*?</p>

If you restrict the second regex to text matched by the first, you'll get all the <p> tags that are inside a <div> tag, and none of the other <p> tags the file may contain.

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us