Re: Simple RegEx Question
- From: Bryan A <Galatorg@xxxxxxxxx>
- Date: Sat, 14 Mar 2009 17:40:47 -0700 (PDT)
On Mar 14, 5:32 pm, Curtis Dyer <dye...@xxxxxxxxxxx> wrote:
Bryan A <Galat...@xxxxxxxxx> wrote in comp.lang.php:
So I have something exactly like the following string in every one of
db entries. I was going to loop through and delete just that string.
My problem is with the deleting part (I am new to regex).
What I need deleted:
(a1 | b8)
So how would I remove that from a string? The numbers aren't always
going to be 1 and 8 so I assume a wild card would go there.
Thanks for any help,
Bryan
Do the letters preceding the numbers change? It doesn't seem like
you indicated they do, so maybe try this:
/* Use /i modifier for case insensitive matching. */
$re = '% \( a\d \s+ \| \s+ b\d \) %x';
$data = 'Test test (a2 | b7) test test.';
if (preg_match($re, $data, $m, PREG_OFFSET_CAPTURE)) {
printf("Matched data: %s\nOffset at which match starts: %d\n",
$m[0][0], $m[0][1]);
}
--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Thanks, that is exactly what I was looking for
.
- References:
- Simple RegEx Question
- From: Bryan A
- Re: Simple RegEx Question
- From: Curtis Dyer
- Simple RegEx Question
- Prev by Date: Re: Simple RegEx Question
- Next by Date: Re: Small help with PHP / AJAX
- Previous by thread: Re: Simple RegEx Question
- Next by thread: Re: Simple RegEx Question
- Index(es):
Relevant Pages
|