php-windows | 2003112
Date: 11/21/03
- Next message: Eric COLINET: "Re: [PHP-WIN] Compiling"
- Previous message: Andrei BEJENARU: "[PHP-WIN] Re: Regular Expression Question"
- Maybe in reply to: Andrei BEJENARU: "[PHP-WIN] Re: Regular Expression Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Okay, thanks for pointing that out.
How do we place multiple Replacements in the $replacement argument to preg_replace? I've added a double capture on my regular expression. If it is matched then I replace the the matched pattern by prefix a single character the the value of ${1} from the captured pattern. I have found out that I may need a second expression to capture all of the items in the file
<snip>
$aStr = array();
$aPat = array();
$aSum = array();
$aStr[] = "1. This is my first Qna";
$aStr[] = " 1. This is my first Qna";
$aStr[] = "11. This is my first Qna";
$aPat[] = "/(^\d{1,2}\.)|(^\s\d{1,2}\.)/";
$aPat[] = "/(^\d{1,2}\.)|(^\s\d{1,2}\.)/";
$aPat[] = "/(^\d{1,2}\.)|(^\s\d{1,2}\.)/";
****problem is here
$rep = "Q\${1}, ${2}";
$aSum = preg_replace($aPat, $rep, $aStr);
echo "<P>";
foreach( $aSum as $s )
{
echo "string = $s <BR>";
}
-- Gerardo S. Rojas mailto: grojas <email protected>-----Original Message----- From: Andrei BEJENARU [mailto:abejenaru <email protected>] Sent: Friday, November 21, 2003 9:50 AM To: php-windows <email protected> Subject: [PHP-WIN] Re: Regular Expression Question
Enclose a capturing group (\d) and the use prefix\${1} inside the replacement. Check out the PHP manual:
$string = "April 15, 2003"; $pattern = "/(\w+) (\d+), (\d+)/i"; $replacement = "\${1}1,\$3";
"Gerardo Rojas" <grojas <email protected>> wrote in message news:F0EDCD6B96C14741A2F6B0BE6EB7D9CF6D703B <email protected> I have a regular expression, that finds what i want. The problem lies in that I don't want to replace this pattern with another. I want to prefix the pattern with a character. Any suggestions as to how I might accomplish this?
regular expression = '/^\d\{1,2}\./'
-- Gerardo S. Rojas mailto: grojas <email protected>
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: Eric COLINET: "Re: [PHP-WIN] Compiling"
- Previous message: Andrei BEJENARU: "[PHP-WIN] Re: Regular Expression Question"
- Maybe in reply to: Andrei BEJENARU: "[PHP-WIN] Re: Regular Expression Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

