I am reading a text file and want to use regex below to pull out numbers with exactly 5 digit, ignoring alphabets Try this var str = 'f 34 545 323 12345 54321 123456', matches = str. Match(/\b\d{5}\b/g); console. Log(matches); // "12345", "54321" jsFiddle The word boundary be is your friend here Update My regex will get a number like this 12345 but not like a12345 The other answers provide great regexes if you require the latter.
I am reading a text file and want to use regex below to pull out numbers with exactly 5 digit, ignoring alphabets. Try this... var str = 'f 34 545 323 12345 54321 123456', matches = str. Match(/\b\d{5}\b/g); console.
Log(matches); // "12345", "54321" jsFiddle. The word boundary \b is your friend here. Update My regex will get a number like this 12345, but not like a12345.
The other answers provide great regexes if you require the latter.
– Joel Etherton Feb 12 at 1:21 @Joel Etherton Just tried it, and it didn't match it. I'm probably missing something, please elaborate for me :) – alex Feb 12 at 1:22 @alex - My comment was made when you had it at str. Match(/\d{5}/g); and it did match it.
– Joel Etherton Feb 12 at 1:26 @Joel Etherton Yeah, it was a rushed answer and incorrect. Hopefully this new one is OK :) – alex Feb 12 at 1:27 55555hallo will not be matched right? – Luke Feb 12 at 1:28.
My test string for the following: testing='12345,abc,123,54321,ab15234,123456,52341'; If I understand your question, you'd want "12345", "54321", "15234", "52341". If JS engines supported regexp lookbehinds, you could do: testing. Match(/(?Match(/(?:^|\D)(\d{5})(?=\D|$)/g) and remove the leading non-digit from appropriate results, or: pentadigit=/(?:^|\D)(\d{5})(?=\D|$)/g; result = ; while (( match = pentadigit.
Exec(testing) )) { result. Push(match1); } Note that for IE, it seems you need to use a RegExp stored in a variable rather than a literal regexp in the while loop, otherwise you'll get an infinite loop.
Good looking results there, +1. – alex Feb 12 at 1:38.
1 It does work :) – alex Feb 12 at 1:38 Although it isn't clear whether he wants to match the 23553 in d23553 or not... Vague questions are so annoying! – Mark Eirich Feb 12 at 1:41 .. and if the OP does want to match d23553, my regex is quite inadequate! :P – alex Feb 12 at 1:43.
D(\d{5})\D This will do on: f 23 23453 234 2344 2534 hallo33333 "50000" 23453, 33333 50000.
Regexr. Com?2t385 – Luke Feb 12 at 1:37 What if the string is 12345? JsFiddle – alex Feb 12 at 1:41 hm, yeah your right, so the point goes to @outis +1 – Luke Feb 12 at 1:45.
From the variable, want to grab out all numbers with the pattern of exactly 5 digits. No need to care of whether before/after this digit having other type of words. Just want to make sure whatever that is 5 digit numbers been grabbed out.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.