Reputation: 277
how to get phone number drom next files name
I need to get in one step
now i use (\d{4,})[^(9902])] but on short numbers is wrong
Upvotes: 0
Views: 100
Reputation: 174696
You could use the below regex which matches upto 9902 or ] symbol,
(?<=[A-Z] ).*?(?=9902|])
OR
(?<=[A-Z] )\d+?(?=9902|])
Upvotes: 0
Reputation: 46841
You can try with Lookaround
(?<=\[[A-Z] )\d+?(?=9902\]|\])
online demo and tested at regexstorm
Pattern explanation:
(?<= look behind to see if there is:
[[A-Z] any character of: '[', 'A' to 'Z'
) end of look-behind
\d+? digits (0-9) (1 or more times)
(?= look ahead to see if there is:
9902] '9902]'
| OR
] ']'
) end of look-ahead
Upvotes: 0
Reputation: 19830
You are searching for square bracket, than letter, than space, than 1+ digits, than quare bracket. So the regular expression is: [\[][A-Z].\d+[\]]
But because you want to ezxtract only 1+ digits (number) you need to group them using ()
, so regex is [\[][A-Z].(\d+)[\]]
Then the rest of the code is simple:
Regex regexp = new Regex("[\[][A-Z].(\d+)[\]]");
foreach(var mc in qariRegex.Matches(yourstring))
{
Console.Writeln(mc[0].Groups[1].Value);
}
Upvotes: 0