Page 1 of 1
regex problems
Posted: Thu Sep 23, 2004 11:59 pm
by bimo
Sami | Topic title changed for clarity.
Okay, I've started working on this project again and I'm still having regex problems. In my last question, the solution that I proposed, (^.*\D), worked for picking all of the non-number characters off of the beginning of a string. However, I now want that length of letters back so I can use it. The length of characters can be of different lengths, too.
I've tried
and
among other pregs. I even tried
Code: Select all
ereg("[[:<:]]), $indiv_match, $programa_encontrada)
Nothing wooooorrrrks...
I'd really appreciate a little help. Thanks
Posted: Fri Sep 24, 2004 12:19 am
by feyd
can you explain more of what you are wanting this time? I'm not sure about this part
However, I now want that length of letters back so I can use it.
your topic subject needs a bit of work.

Posted: Fri Sep 24, 2004 5:13 am
by m3mn0n
feyd wrote:your topic subject needs a bit of work.

Not anymore.
bimo, it's best to describe the problem a little in the title. That way maybe someone very good with whatever problem your having can have their attention caught, and can read your problem.
Posted: Fri Sep 24, 2004 8:31 am
by bimo
right, sorry. It was late...
Well, it's a simple problem very similar to my last question about taking the last six digits off of a string. The difference is that now I want to take the letters off of the beginning of the string but an indeterminate # of letters.
First thing I thought I'd try was preg_split with PREG_SPLIT_DELIM_CAPTURE and put the two different halves into an array. I didn't know what regex to use, though and figured preg_split would be a more immediate solution that would take the least ammount of readjustment to my code to get it to work.
I put a couple of examples of the things that I tried last night (I tried many more but didn't save them).
I hope that this is more clear. Sorry about before. It was late... I was tired... Probably should have just gone to bed.
thanks
Posted: Fri Sep 24, 2004 8:32 am
by bimo
here is
Posted: Fri Sep 24, 2004 12:29 pm
by feyd
the regex I posted last time will do this.
feyd wrote:not really...
this is for a preg_* function...
Posted: Sat Sep 25, 2004 12:23 am
by bimo
thanks again, feyd. I had been trying that regex but wasn't leaving the hashes in (I;ve never seen regexes written like this and the book I'm using only has a short chapter of them.) So I tried leaving them in and, what do you know, it worked after all.
Thanks again.
Posted: Sat Sep 25, 2004 12:34 am
by feyd
that's why I specified it's for a preg_* function. the preg_* functions have pattern start and stop symbol markers, so you can add modifiers to alter how the regex runs.
Posted: Tue Sep 28, 2004 4:51 pm
by bimo
Right. I have used preg_match once but m regex did''t have hashes. I was expecting backslashes for the start/stop symbolss. Here's what I used before:
Code: Select all
<?php$google_pattern = "/<textarea name=q rows=5 cols=45 wrap=PHYSICAL>([^<]*)<\/textarea>/i";
preg_match($google_pattern, $google_result, $google_trans);
?>
is there a difference between the #'s and the /'s?
Posted: Tue Sep 28, 2004 5:00 pm
by feyd
nope.. it can be any symbol (generally). I use hashes because forward slashes are in a lot of my regex patterns.

Posted: Tue Sep 28, 2004 5:46 pm
by bimo
great to know. Thanks.
is there a way to say "or" in a regex? for instance, "take all characters in the string until you reach a backslash OR a number"?
Posted: Tue Sep 28, 2004 6:34 pm
by feyd
Code: Select all
preg_match('#^[^\\\\\\\\0-9]*#',.......)