Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Question for someone who is really good with regular expressions (REGEX)?
How would you write a regular expression that matches a string xxxxxxxxxxxxxx,
where xxxxxxxxxxx contains at least 7 digits, and does not contain any letters?
TIA
4 Answers
- ArmchairPilotLv 61 decade agoFavorite Answer
A regex does not match permutations, just patterns
Here's a solution: This method sorts the original string and then tests for at least 7 digits and no letters
var strX = "1&2#2@2&2@2@2@.//22";
strX = strX.split("").sort().join("");
var regexp = /.*\d{7,}[^a-zA-Z]*$/;
alert(strX.match(regexp));
"1&2#2@2&2@2@2@X//22" alerts null (has an X)
",&[#]@2&2@2@2@.//22" alerts null (only 5 digits)
with the sorted string, there are no letters preceding the digits which are all grouped together
.* - any number of characters, all of which have ASCII < 48 (excludes letters)
\d{7,} - at least 7 characters
[^a-zA-Z]*$ - no letters to the end of the string
- ?Lv 45 years ago
attempt this: .*187ef4436122d1cc2f40dc2b92f0eba0187ef4436122d1cc2f40dc2b92f0eba0.*c.*de.* The 187ef4436122d1cc2f40dc2b92f0eba0sterisks 187ef4436122d1cc2f40dc2b92f0eba0re no longer wild c187ef4436122d1cc2f40dc2b92f0eba0rds such as you 187ef4436122d1cc2f40dc2b92f0eba0re used to in different forms of glo187ef4436122d1cc2f40dc2b92f0eba0187ef4436122d1cc2f40dc2b92f0eba0ing. They indic187ef4436122d1cc2f40dc2b92f0eba0te "0 or extra occurences of the previous." The squ187ef4436122d1cc2f40dc2b92f0eba0re 187ef4436122d1cc2f40dc2b92f0eba0r187ef4436122d1cc2f40dc2b92f0eba0ckets me187ef4436122d1cc2f40dc2b92f0eba0n "a sort of", so [187ef4436122d1cc2f40dc2b92f0eba0187ef4436122d1cc2f40dc2b92f0eba0] won't m187ef4436122d1cc2f40dc2b92f0eba0tch "187ef4436122d1cc2f40dc2b92f0eba0187ef4436122d1cc2f40dc2b92f0eba0" 187ef4436122d1cc2f40dc2b92f0eba0ut it is going to m187ef4436122d1cc2f40dc2b92f0eba0tch "ab" or "ab". The sessions (.) 187ef4436122d1cc2f40dc2b92f0eba0re the closest you h187ef4436122d1cc2f40dc2b92f0eba0ve to wild c187ef4436122d1cc2f40dc2b92f0eba0rds.
- 1 decade ago
Isn't is as simple as:
m/\d{7,}/
Or does xxxxxxx contain other not digit and non letter characters?
Source(s): man regex - Anonymous1 decade ago
What language?