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# / March 2008

Tip: Looking for answers? Try searching our database.

Regex to with whitespace or tab or newline, can't seem to get it to     work.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DotNetNewbie - 08 Mar 2008 18:24 GMT
Hi,

I have text in a file that looks like this:

[
                                           2
                                           in stock]

What kind of regex could get the '2' ?

I tried this:

string regex = @"[\s]*(?'stock'.*?).*in\sstock]";

But it didn't work since [\s]*  doesn't include tabs etc, and I am not
sure exactly what that whitespace is.....
Arne Vajhøj - 08 Mar 2008 23:23 GMT
> I have text in a file that looks like this:
>
[quoted text clipped - 3 lines]
>
> What kind of regex could get the '2' ?

Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !

Arne
DotNetNewbie - 09 Mar 2008 00:40 GMT
> > I have text in a file that looks like this:
>
[quoted text clipped - 7 lines]
>
> Arne

\d+ is for digits, but that area might contain whitespace, tabs or
carriage returns also.
Arne Vajhøj - 09 Mar 2008 00:47 GMT
>>> I have text in a file that looks like this:
>>> [
[quoted text clipped - 5 lines]
> \d+ is for digits, but that area might contain whitespace, tabs or
> carriage returns also.

If it contains whitespace then what do you want returned ?

Arne
DotNetNewbie - 09 Mar 2008 01:49 GMT
> >>> I have text in a file that looks like this:
> >>> [
[quoted text clipped - 9 lines]
>
> Arne

The integer value 2.
Arne Vajhøj - 09 Mar 2008 01:53 GMT
>>>>> I have text in a file that looks like this:
>>>>> [
[quoted text clipped - 7 lines]
>
> The integer value 2.

If it does not contain any digits but only whitespace at that
position you want it to return 2 ??

Arne
DotNetNewbie - 09 Mar 2008 02:58 GMT
> >>>>> I have text in a file that looks like this:
> >>>>> [
[quoted text clipped - 12 lines]
>
> Arne

The text is like this:

[
          2
       in stock]

All that whitespace could be: 1) whitespace 2)carriage return 3) tabs

I want to extract the integer value (in the example I'm giving it is
2).
Arne Vajhøj - 09 Mar 2008 04:15 GMT
>>>>>>> I have text in a file that looks like this:
>>>>>>> [
[quoted text clipped - 19 lines]
> I want to extract the integer value (in the example I'm giving it is
> 2).

\s matches space, CR and TAB !

So I do still not understand the problem.

Arne
DotNetNewbie - 10 Mar 2008 15:51 GMT
> >>>>>>> I have text in a file that looks like this:
> >>>>>>> [
[quoted text clipped - 25 lines]
>
> Arne

Ok I got it to work!

Rate this thread:







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.