Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

Regex

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AMP - 02 Apr 2008 14:46 GMT
Hello,
I have a Regex:
           Regex regex = new Regex(@"22 22 22 22 22 22 22 22 22 22(?
<centervalue>.+)33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33");

Sometimes my data has 10 sets of "22"'s , sometimes 12, 14 ,ect.
I want the centervalue to start  after ALL of the "22"'s but this is
not happening.
Once it see's the 10 sets it starts there, but I want it to start at
the end, no matter how many sets.
Any suggestions?
Thanks,
Mike
Ethan Strauss - 02 Apr 2008 15:29 GMT
You want to specificy at least 10 repeats like this
     Regex regex = new Regex(@"(22 ){10,}(?
<centervalue>.+)(33 ){minimum allowable number,}");

I think that will do it.
If you enclose something in curly braces and follow it by the following
strings, you will get the following number of matches (from C# in a Nutshell
edition something)
*                      Any number of matches (including zero)
+                      At least 1 match
?                      Exactly 1 match
{n}                   Exactly n matches
{n,}                 At least n matches
{n,m}              At least n matches, No more than m matches

Ethan

> Hello,
> I have a Regex:
[quoted text clipped - 10 lines]
> Thanks,
> Mike
AMP - 02 Apr 2008 15:46 GMT
On Apr 2, 10:29 am, Ethan Strauss
<EthanStra...@discussions.microsoft.com> wrote:
> You want to specificy at least 10 repeats like this
>       Regex regex = new Regex(@"(22 ){10,}(?
[quoted text clipped - 29 lines]
>
> - Show quoted text -

I'm getting:
"parsing \"(22 ){10,}(? <centervalue>.+)(33 ){10,}\" - Unrecognized
grouping construct."

Mike
Ethan Strauss - 02 Apr 2008 16:01 GMT
There is an extra space after your question mark and before the less than

should be
(22 ){10,}(?<centervalue>.+)(33 ){10,}
not
(22 ){10,}(? <centervalue>.+)(33 ){10,}

At least this takes care of the parsing error. I have not tested it for real
functionality.
Ethan

> On Apr 2, 10:29 am, Ethan Strauss
> <EthanStra...@discussions.microsoft.com> wrote:
[quoted text clipped - 37 lines]
>
> Mike
KH - 02 Apr 2008 18:28 GMT
How about:

string str = "22 22 22 22 22 22 My Value 33 33 33 33 33 33 33";

int start = str.LastIndexOf(" 22") + 3;
int end = str.IndexOf(" 33);

// Now you have the start and end locations of the value you're looking for
and can use SubString to parse it out, or a RegEx if you need more complex
parsing logic for it.

HTH

> Hello,
> I have a Regex:
[quoted text clipped - 10 lines]
> Thanks,
> Mike

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.