RegExp violation: every line that is less than or equal to "001700",

I have a unique task.

I want to create a google analytics filter for a custom variable that only returns a value if the given string is less than or equal to 001700. yes, I know that the string cannot be less, but I need to find a way to make this work.

oh, and if you ask: there is no way to convert this string to a number (according to my knowledge - through the Google analytics filter), in which case I need to work.

so basically i have

000000
000001
000002
000003
...
...
999998
999999

and I need a regular expression that matches

001700
001699
001698
...
...
000001
000000

but does not match

001701
001702
...
...
999998
999999

sub question a) is this possible? (as I found out, everything is possible with regExp if you are smart and / or masochistic enough)

sub question b) ?

+3
3

:

^00(1700|1[0-6][0-9]{2}|0[0-9]{3})$

+4

RegEx:

/00(1([0-6][0-9]{2}|700)|0[0-9]{3})/

:

00,

  • 1, 0-6 2 = 1000 - 1699

  • 1700

  • 0, 3 = 0000 - 0999
+1

yes you can do

see this article

For instance:

alert('your numericle string'.replace(/\d+/g, function(match) {
    return parseInt(match,10) <= 17000 ? '*' : match;
}));

JavaScript calls our function, passing the match to our match argument. Then we return either an asterisk (if the number corresponds to less than 17000) or the match itself (i.e., a match should not take place).

+1
source

All Articles