...

View Full Version : Regex, get part of string



Bencori
05-25-2011, 06:51 PM
Hello to everyone it's my first post here. I am looking for a really nice coding forums for quite a while now, I do different languages, I like polite and respecful communities, hope here will be the place.

Anyway, I'm facing a problem I could do with someone's help:

I'm trying to make a regex that would return only a number from a BBCode string. Like this:



bla bla bla bla


I only want "50". So I could do it the dirty way, but I'm looking for a better way to "exclude" 50.

So I make my pattern, like this:



#\[bbcode\=[0-9]*\](.*?)\[\/bbcode\]#


I think the expression above should match anything between my tags.

Now, what I'm trying to extract the number before the replace. Anyone knows how to do this?

Thanks.

Inigoesdr
05-25-2011, 09:29 PM
#\[bbcode\=([0-9]*)\](.*?)\[\/bbcode\]#
The number argument will be match 1 and the content in the tags will be match 2.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum