Results 1 to 3 of 3

Thread: RegEx question

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    RegEx question

    Two samples of source:

    <tag>45</tag>
    <tag>395</tag>

    (The real source is of course more stuffed with attributes and so on)

    I want to filter out the number, regardless if it it's 2 or 3 numbers.
    I know how to match with 2 numbers, or three numbers but not both at the same time

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: RegEx question

    I assume you're doing \d{2} and \d{3} for matching 2 or 3 numbers? (If you're still doing \d\d and \d\d\d, you should read up on "Quantifiers")
    \d{2,3} will match at least 2 but no more than 3. (so, note that \d{2,4} for example would match 3 numbers, the two arguments are the minimum and maximum, it is not a list of acceptable lengths)

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: RegEx question

    <(tag)\b[^>]*>(\d{1,5})</\1>

    This should get you any number between any tags of 1 to 5 digits,ignoring any other attributes in the tag. Change tag to match whatever your tag is and {1,5} to specify the minimum & maximum digits in the number.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

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



Click Here to Expand Forum to Full Width