regex problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

regex problems

Post 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

Code: Select all

preg_match /"(^.*\D)"/...
and

Code: Select all

preg_match("/(^.*)\D/"
among other pregs. I even tried

Code: Select all

ereg("[[:<:]]), $indiv_match, $programa_encontrada)


Nothing wooooorrrrks...

I'd really appreciate a little help. Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

feyd wrote:your topic subject needs a bit of work. :?
Not anymore. :wink:

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.
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post 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
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

here is
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the regex I posted last time will do this.
feyd wrote:not really...

Code: Select all

#^(&#1111;^\d]*)#
this is for a preg_* function...
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

nope.. it can be any symbol (generally). I use hashes because forward slashes are in a lot of my regex patterns. :)
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post 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"?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

preg_match('#^[^\\\\\\\\0-9]*#',.......)
Post Reply