-
Jul 11th, 2011, 05:41 PM
#1
Thread Starter
Hyperactive Member
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
-
Jul 11th, 2011, 07:24 PM
#2
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)
-
Jul 11th, 2011, 11:47 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|