473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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.....
Mar 8 '08 #1
8 1535
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)" !

Arne
Mar 8 '08 #2
On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
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)" !

Arne
\d+ is for digits, but that area might contain whitespace, tabs or
carriage returns also.
Mar 9 '08 #3
DotNetNewbie wrote:
On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>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
Mar 9 '08 #4
On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
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.
Mar 9 '08 #5
DotNetNewbie wrote:
On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>DotNetNewbie wrote:
>>On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
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
Mar 9 '08 #6
On Mar 8, 8:53 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
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).
Mar 9 '08 #7
DotNetNewbie wrote:
On Mar 8, 8:53 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>DotNetNewbie wrote:
>>On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>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
Mar 9 '08 #8
On Mar 8, 11:15 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 8:53 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 7:47 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
On Mar 8, 6:23 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
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!
Mar 10 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Seb | last post by:
Hi, Has anyone an idee how i can replace every character in a string if it is not alphanumeric ? something like eregi_replace, but i don't know how i say in regex NOT. Tnx
5
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website...
16
by: qwweeeit | last post by:
In analysing a very big application (pysol) made of almost 100 sources, I had the need to remove comments. Removing the comments which take all the line is straightforward... Instead for the...
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
1
by: Thief_ | last post by:
I'd like to check if a textbox contains text & symbols. Sometimes it will have just carriage returns and/or spaces, and lots of them, and I want to check if this is the case so that I can clear the...
2
by: Craig Buchanan | last post by:
I have a HTML fragment that looks like this: <tr> <td valign="top" nowrap><span class="textBold">Property ID: </span></td> <td valign="top" nowrap colspan="4"...
1
by: David | last post by:
I have rows of 8 numerical values in a text file that I have to parse. Each value must occupy 10 spaces and can be either a decimal or an integer. // these are valid - each fit in a 10 character...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
4
by: CJ | last post by:
Is this the format to parse a string and return the value between the item? Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>"); I am trying to parse this string. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.