Click here to Skip to main content
15,898,732 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
how to match (n) or (-n) less Then n number of character within a given string ...

suppose i have one string like>>
ABCDEFGHIJKLMNOP....YZ

Pattern To be search>>
LMNOPQ{-5}UVWX

i want to match n or less then n no of char ...

How to Get That ...
Thanks in advance

Any Suggestions will be appreciated...
Posted

1 solution

Don't do it with a regex - they are text matching systems, not text processing. They don;t have any provision for converting substrings to numbers, so your regex would have to explicitly check for {1}, {2}, {3}, ... {999} which is ridiculous (and error prone).

Instead, do a Regex which finds the number - that's trivial - and then extract the substring after it in C# or VB. The Match object that the regex returns includes the Index and Length of the matched text, so extracting the substring after that is trivial in either language.
 
Share this answer
 
Comments
Member 10521418 24-Jul-15 14:17pm    
Thnk you for the info ....
as u said first check the index where first pattern match and then calculate with other method to get check n or -n no of byte ...

but m pattern is like this only ABCD{-3}JKL ...
to match 3 or less then 3 character how to get that nd by which method in c# or .net ....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900