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

D

DotNetNewbie

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.....
 
A

Arne Vajhøj

DotNetNewbie said:
I have text in a file that looks like this:


[
2
in stock]



What kind of regex could get the '2' ?

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

Arne
 
A

Arne Vajhøj

DotNetNewbie said:
DotNetNewbie said:
I have text in a file that looks like this:
[
2
in stock]
What kind of regex could get the '2' ?
Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !

\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
 
D

DotNetNewbie

DotNetNewbie said:
DotNetNewbie wrote:
I have text in a file that looks like this:
[
2
in stock]
What kind of regex could get the '2' ?
Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !
\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

The integer value 2.
 
A

Arne Vajhøj

DotNetNewbie said:
DotNetNewbie said:
DotNetNewbie wrote:
I have text in a file that looks like this:
[
2
in stock]
What kind of regex could get the '2' ?
Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !
\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 ?

The integer value 2.

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

Arne
 
D

DotNetNewbie

DotNetNewbie said:
DotNetNewbie wrote:
DotNetNewbie wrote:
I have text in a file that looks like this:
[
2
in stock]
What kind of regex could get the '2' ?
Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !
\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 ?
The integer value 2.

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

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).
 
A

Arne Vajhøj

DotNetNewbie said:
DotNetNewbie said:
DotNetNewbie wrote:
DotNetNewbie wrote:
I have text in a file that looks like this:
[
2
in stock]
What kind of regex could get the '2' ?
Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !
\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 ?
The integer value 2.
If it does not contain any digits but only whitespace at that
position you want it to return 2 ??

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).

\s matches space, CR and TAB !

So I do still not understand the problem.

Arne
 
D

DotNetNewbie

DotNetNewbie said:
DotNetNewbie wrote:
DotNetNewbie wrote:
DotNetNewbie wrote:
I have text in a file that looks like this:
[
2
in stock]
What kind of regex could get the '2' ?
Try @"(\d+)(?:\s+in stock)" or @"(\d+)(?:\s+in\s+stock)" !
\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 ?
The integer value 2.
If it does not contain any digits but only whitespace at that
position you want it to return 2 ??
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).

\s matches space, CR and TAB !

So I do still not understand the problem.

Arne

Ok I got it to work!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top