Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regex, get part of string

    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:

    Code:
    [bbcode=50]bla bla bla bla[/bbcode]
    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:

    Code:
    #\[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.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Code:
    #\[bbcode\=([0-9]*)\](.*?)\[\/bbcode\]#
    The number argument will be match 1 and the content in the tags will be match 2.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •