<img alt="" src="https://secure.agile365enterprise.com/790157.png" style="display:none;">

The ultimate tool for matching 'strings'

author
By Team Srijan Aug 26, 2008
The ultimate tool for matching 'strings'
The ultimate tool for matching 'strings'

As per client project requirement, I had to do some string matching ...... and behold, Ahm... that too keeping the pattern intact.

So googled through the few pages, then suddenly came with an idea to give a try to regular expression [regexp]. Now who is going to help me out.

Bingo!! take help from PJ [Our Sys Admin]. Hey PJ can you help me out with the problem. Sure , he forwarded with a link and page 192 of the OReilly book for perl. Hmmm... now i got some idea.

Tried to combine both googled page and reference from the book and that resolved my worries. 

Challange: <ab-cd>Some text</ab-cd> <de-fg> Some text</de-fg> ..... Take out all the tags and keep the text between the tags in order. 

Solution: [php] preg_match_all

$pattern = "/(<([\w\-]+)[^>]*>)(.*)(<\/\\2>)/"; preg_match_all($pattern,$content,$out, PREG_PATTERN_ORDER); $out[2] will display an array of matched tags $out[3] will display an array of text with the matched tags.

Subscribe to our newsletter