Re: regular expression problem



condor wrote:
Karel de Vos wrote:
I think you want "\[([^\]]*?)\]"

I don't know what that should do. But when I try it (php ereg_replace)
I get an error message.

It is a perl regular expression:
$text = "This [is my'text] that is [between brackets] and so on..";
preg_match_all("/\[([^\]]*?)\]/",$text,$matches);
// now $matches[1] contains the text between the brackets in an array
print_r($matches[1]);

\] matches the character ] (and should be escaped as ] is the group closing bracket
*? matches the smallest portion (zero or more) characters that is not \]. as I think of it, the question mark can be left out since the expressions states that the character cannot be a \] and must be followed by a \]
.



Relevant Pages

  • Re: How to destroy Leopard/Vista/Dragon, all at one fell swoop
    ... I prefer to use words to get across meaning, as in "hex zero", which is ... winded technical explanation about characters, bytes, numbers, ... Try explaining "hex notation" to an unknowledgeable reader, ...
    (comp.sys.mac.system)
  • Re: File IO-I am defeated!
    ... So add some code to trap the error and have the error routine run the code I posted in my last response, except change my code so that it send its output to a log file instead of to a ListBox. ... You are telling us that these files contain only "standard text characters", and that you have produced them using your own code so you are certain you are correct. ... Your own code will happily load a file containing whatever bytes values you wish, whether they are what you would call standard text characters or not, EXCEPT it will fail with exactly the error you describe if there is a Chror a Chranywhere in the file. ... I would bet my bottom dollar that when you eventually get the log back from the faulty file you will find at least one of those characters in there, most probably the zero. ...
    (microsoft.public.vb.general.discussion)
  • Re: strncmp(a,b,0)
    ... > Now I have it to return zero. ... characters (characters that follow a null character are not ... or less than the possibly null-terminated array ... Don't you think one empty string is equal to another empty string? ...
    (comp.lang.c)
  • Re: A question about procmailrc
    ... Zero or more characters, zero or more colons, ... another zero or more characters, ... My .procmailrc put the mail in Junk -- working. ...
    (Fedora)
  • Re: fread returns more than i want
    ... But now at the end of each part of the file I get some strange characters and the last block continues again ... In particular, if buf lacks a zero terminator it is not a proper string, and passing it to fprintf() invokes undefined behavior. ...
    (comp.lang.c)