Padding a page range
Posted: Fri Jul 13, 2012 8:15 pm
I've found several similar questions on the forum, but nothing quite like what I need.
I'm screen-scraping data from a website, fielding it, and entering it in a database. One field is PAGE_RANGE, basically, the starting and ending page numbers of a journal article. The website presents the data in a truncated form, by dropping repeated "most significant digits" from the second number, but I have to store the full starting and ending page numbers.
So we'll see data like this, and I need it to turn into ==> that
156-9 ==> 156-159
45-55 ==> 45-55 (no change needed here because all digits are there)
989-1004 ==> 989-1004 (ditto ... no change needed)
10487-92 ==> 10487-10492
Another way to state the problem is this: if the second number has fewer digits than the first, copy enough of the most significant digits from the first number and prepend them to the second one.
Any help very gratefully welcome ... as would an authoritative "sorry, regex can't do that" so I can stop trying. I know I can do this in Excel, so my Plan B is to use that for a clean-up pass after the data is in the database table.
--Eric Ressner
--St Louis MO USA
I'm screen-scraping data from a website, fielding it, and entering it in a database. One field is PAGE_RANGE, basically, the starting and ending page numbers of a journal article. The website presents the data in a truncated form, by dropping repeated "most significant digits" from the second number, but I have to store the full starting and ending page numbers.
So we'll see data like this, and I need it to turn into ==> that
156-9 ==> 156-159
45-55 ==> 45-55 (no change needed here because all digits are there)
989-1004 ==> 989-1004 (ditto ... no change needed)
10487-92 ==> 10487-10492
Another way to state the problem is this: if the second number has fewer digits than the first, copy enough of the most significant digits from the first number and prepend them to the second one.
Any help very gratefully welcome ... as would an authoritative "sorry, regex can't do that" so I can stop trying. I know I can do this in Excel, so my Plan B is to use that for a clean-up pass after the data is in the database table.
--Eric Ressner
--St Louis MO USA