I'm extracting a string of numbers The numbers are either 7 digits or they are 9 digits. Exactly 7, or exactly 9. If it's 8 or its 10 I don't want it to extract anything. I've tried looking on here and none of the expressions are working for me. I've tried the following.
/[0-9]{7}|[0-9]{9}/
-- This gives me the first 7 digits only. If it is 8 digits or 9 digits I only get the first 7.
/[0-9]{7}([0-9]{2})?/
-- Will give me 7 digits. If it is 8 digits it gives me the first 7. If it is 9 digits it gives me 9. I need only 7, or only 9.
/^(\d{7}|\d{9})$/
-- Doesn't work at all unless I remove the carrot and the $, and then it works just like the first expression example.
I don't understand why | as an "or" isn't working.
I know \d is the modern regex shorthand, but the application cannot compile that way. I get an error saying "Don't escape other characters than of "[].\ (){}?+*<>|^"." .