0

I've some pages with this URL

folder/t_01_class.shtml

with a sequential number

folder/t_02_class.shtml
folder/t_03_class.shtml
folder/t_10_class.shtml
folder/t_11_class.shtml
folder/t_12_class.shtml
folder/t_23_class.shtml

and I need to get variable with regex that don't considers first zero so the result should be

<!--#set var="page" value="2"-->
<!--#set var="page" value="3"-->
<!--#set var="page" value="10"-->
<!--#set var="page" value="11"-->
<!--#set var="page" value="12"-->
<!--#set var="page" value="23"-->

any suggestion

Thanks

roybatty
  • 191
  • 3
  • 13

2 Answers2

3

If the regex is acting against the entire page name requested in the URL, I'd suggest using something along the lines of /t_0*([1-9]\d*)_/ and then retrieving numbered group 1.

To clarify that regex:

// around each end are delimiters signifying the regex itself, they are not an active part of the matching.

t_ will match the beginning of the page

0* will match any leading 0's

[1-9]\d* will match any number starting in 1-9, and 0 or more subsequent digits (\d is the equivalent of [0-9], and * after \d means "0 or more")

() around the bit above will make this a numbered group, allowing you to retrieve the match

_ at the end is to ensure that the number match is complete

bdx
  • 3,316
  • 4
  • 32
  • 65
2
[1-9][0-9]*

will match any integer number greater than zero, dropping leading zeroes.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561