-
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 :confused:
-
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)
-
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.