faqts : Computers : Programming : Languages : PHP : Common Problems : Regular Expressions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

How do I find two patterns in a line with arbitrary number of characters between ?

Dec 1st, 2003 12:52
Jakub Vrana, Thomas Svensson,


With curly braces. Be warned about PHP interpretation of {$var} inside 
a string - it's evaluated as $var. So you must escape the brace or 
don't put variable inside a string.
<?php
$distance = 9;
ereg("patt1.{" . $distance . "}patt2", "patt1_2_4_6_8_patt2"); // true
ereg("patt1.{" . $distance . "}patt2", "patt1_patt2"); // false
?>
.{10} means 10 arbitrary characters.