can anyone please help me with regex pattern which matches string like "Viewing 1 to x of n" where x and n are any number
Asked
Active
Viewed 50 times
0
-
Have you tried anything yourself yet? If you want debugging help, you can post it here – CertainPerformance Apr 26 '18 at 05:26
-
4StackOverflow is not a free regex service, show us your attempt – MasOOd.KamYab Apr 26 '18 at 05:27
-
provide some example and your efforts – Ajeet Kumar Apr 26 '18 at 05:27
-
Use this https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression – MasOOd.KamYab Apr 26 '18 at 05:29
-
Possible duplicate of [How do you use a variable in a regular expression?](https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression) – MasOOd.KamYab Apr 26 '18 at 05:30
1 Answers
4
This pattern will match your Viewing (.*\d) to (.*\d) of (.*\d)
If you are stuck on having the first number as 1
just replace the first .*\d
with 1
.
And you can retrieve values in matched groups
(basically of values of the three numbers in the string), using details mentioned in this question.
How do you access the matched groups in a JavaScript regular expression?
Edit: Add groups as per suggestion from @Probie

Yogesh_D
- 17,656
- 10
- 41
- 55
-
-
@MasOOd.KamYab Maybe, but the way i read the title says that hes probably looking to find string that have pagination info. Viewing 1 to 2 of 5 or so on. – Yogesh_D Apr 26 '18 at 05:33
-
2Might be worth adding parens around the `.*\d`s so that he can actually retrive his `x` and `n` (which is what I read the question as asking) – Probie Apr 26 '18 at 05:36