Hello, I'm kind of newbie working with regular expression and I came to a dead end. So, this is the code: #HEADER# Agent: 1544662 Rows: 2 Date: 09-12-2010 #DEFINITION# some other informations .... Code (markup): I want to get the content between #HEADER# AND #DEFINITION# Can you give me some clues how to solve this problem? Thanks, Silviu
If it's that simple, you don't need a regular expression. You can just use strpos to find #HEADER# and #DEFINITION# and then substr to get the text between them.
I would do a regular expression, string replace then PHP's built in parser: If you are the one creating the original file, then do it as a INI file: [Section] option = value $string = '#HEADER# Agent: 1544662 Rows: 2 Date: 09-12-2010 #DEFINITION# Variable: value'; $string = preg_replace('/#(.*)#/','[$1]',$string); $string = str_replace(':','=',$string); $test = parse_ini_string($string,true); print_r($test); PHP:
Think of regex as a last resort, not for something that simple. Regex is very slow. Also, when using regex chop the string down to the section that needs searching. Example, if you need to search within a table on an html page reduce to string to that chunk. If the script gets a lot of hits it could make a difference.