However, sometimes you need something a bit more advanced.
For example you need this incremental functionality
- myvol50xx
- myvol51yy
- myvol52zz
In this case you need to follow these steps :
- create a custom filter with regex (e.g. WHERE name REGEXP '${regex}'
Search for the last item by using this regex '^myvol[0-9]{2}.*$
=> Hint : use skip this step if not found ! - Then use the _found property like this :
(volume_last._found)?Integer.parseInt(getRegexMatch(volume_last.name,"^(myvol)([0-9]{2})(.*)$",2))+1:1
This seems complex, but isn't. - If last volume found
- Strip number from last volume
- regex = ^myvol([0-9]{2})(.*)$
This regex will parse your name and create 4 matches (using the brackets)
Match 0 = the full string
Match 1 = the string "myvol"
Match 2 = the number
Match 3 = the suffix
In our case, we grab match 2 (the number) - And increase by 1
- If not found
- Return 1
- Finally use the number to reassemble the new name
'myvol' + padNumber(NEW_NUMBER,2) + 'mysuffix'
The function "getRegexMatch", you can find on my github (https://www.github.com/wfaguy)
Along this function you can find interesting others. I recently added a few new ones like :
- trimEnd
- getRegexMatch
- getLastNumber
- getLastNumberWithSuffix
No comments :
Post a Comment