Re: Simple RegEx Question



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
.



Relevant Pages

  • Re: How to parse output from a command
    ... Does RegEx rely on the .NET framework? ... >> I'm trying to find a way to get any string out of any output. ... >> bypass the DOS command all together, thinking there would be an easy way ...
    (microsoft.public.scripting.vbscript)
  • Re: How to trim a String trailing spaces, but not leading spaces?
    ... I compared the regex to ... Lew's loop proposal. ... short string, which may skew the results also. ... class Compiled extends Test { ...
    (comp.lang.java.programmer)
  • Re: Fastest way to strip NewLine from string (.Net 2, VS 2005)
    ... What is the fastest way to remove line feeds from the end of a string? ... RegEx was too slow. ... I am using a for loop, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: speed problems
    ... So every line the regex is compiled ... You might want to compile the regex outside the loop and only ... The original code posted uses functions from the string module. ...
    (comp.lang.python)
  • Re: Simple RegEx Question
    ... I was going to loop through and delete just that string. ... My problem is with the deleting part (I am new to regex). ... going to be 1 and 8 so I assume a wild card would go there. ...
    (comp.lang.php)