473,408 Members | 1,676 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,408 software developers and data experts.

Watsup with my simple RegExp?

Dim re As New Regex("\s([0-9]+)\s")
Dim mc As Match = re.Match("Puppy measures 13 inches ")
Dim s As String = mc.Groups.Item(0).ToString()

s is " 13 " with a leading and a trailing space, and driving me nuts.
My set of parenthesis clearly specify only digits, where do the spaces
come from???.

What am I doing wrong????

VS2008 .net 3.5
Jun 27 '08 #1
3 794
On Apr 18, 5:06*pm, Jeannot <jean...@hawk.igs.netwrote:
Dim re As New Regex("\s([0-9]+)\s")
Dim mc As Match = re.Match("Puppy measures * * * *13 * * *inches ")
Dim s As String = mc.Groups.Item(0).ToString()

s is " 13 " with a leading and a trailing space, and driving me nuts.
My set of parenthesis clearly specify only digits, where do the spaces
come from???.

What am I doing wrong????
well... the primary match is " 13 " because of the \s so, if you look
at group item 1, it will be 13:

mc.Groups.Item(1).Value

In other words, the expression matches the entire expression, the
parens are a sub match. You could just write it like this:

"\d+"

Dim s As String = "Puppy measures 13 12 inches "
Dim matches As MatchCollection = Regex.Matches(s, "\d+")

For Each m As Match In matches
Console.WriteLine(m.Value)
Next

HTH

--
Tom Shelton
Jun 27 '08 #2

"Jeannot" <je*****@hawk.igs.netwrote in message
news:85**********************************@24g2000h sh.googlegroups.com...
Dim re As New Regex("\s([0-9]+)\s")
Dim mc As Match = re.Match("Puppy measures 13 inches ")
Dim s As String = mc.Groups.Item(0).ToString()

s is " 13 " with a leading and a trailing space, and driving me nuts.
My set of parenthesis clearly specify only digits, where do the spaces
come from???.

What am I doing wrong????

VS2008 .net 3.5
There is always a Group 0 which corresponds to the entire pattern. And of
course your entire pattern does include white space characters. Try the
following:

Dim re As New Regex("\s([0-9]+)\s")
Dim mc As Match = re.Match("Puppy measures 13 inches ")
Dim s As String = mc.Groups.Item(0).ToString()
MsgBox("s is """ & s & """; Length of s is " & s.Length.ToString)

s = mc.Groups.Item(1).ToString()
MsgBox("s is """ & s & """; Length of s is " & s.Length.ToString)

Good Luck, Bob

Jun 27 '08 #3
On Apr 18, 9:18 pm, "eBob.com" <eBob....@totallybogus.comwrote:
"Jeannot" <jean...@hawk.igs.netwrote in message

news:85**********************************@24g2000h sh.googlegroups.com...
Dim re As New Regex("\s([0-9]+)\s")
Dim mc As Match = re.Match("Puppy measures 13 inches ")
Dim s As String = mc.Groups.Item(0).ToString()
s is " 13 " with a leading and a trailing space, and driving me nuts.
My set of parenthesis clearly specify only digits, where do the spaces
come from???.
What am I doing wrong????
VS2008 .net 3.5

There is always a Group 0 which corresponds to the entire pattern. And of
course your entire pattern does include white space characters. Try the
following:

Dim re As New Regex("\s([0-9]+)\s")
Dim mc As Match = re.Match("Puppy measures 13 inches ")
Dim s As String = mc.Groups.Item(0).ToString()
MsgBox("s is """ & s & """; Length of s is " & s.Length.ToString)

s = mc.Groups.Item(1).ToString()
MsgBox("s is """ & s & """; Length of s is " & s.Length.ToString)

Good Luck, Bob
That was it.
Thanks Guys!
Jun 27 '08 #4

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

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
0
by: Alexander Schmolck | last post by:
I sometimes find myself in the situation that I want to perform some simple source code changes, queries etc. in the code regions of a python file (i.e. outside comments and strings). I thought...
2
by: nix | last post by:
Hi I want to create a simple user validation script without using a database. Let's say I have a text file in my asp folder with a list of valid usernames. How can i do something like the...
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
4
by: drasko | last post by:
Hi all. I need to code simple and fast int regexp_match(char *regexp, char *string) function that will follow the expression regexp, and see if there is a matching in the string. If there is, it...
3
by: Grumman | last post by:
For various reasons, I've found myself in the position of needing to automate the operation of a small VB6 application from an external process. After a bit of searching, I found watsup, and it has...
9
by: den | last post by:
if I have: string=/AAA/B/file.jpg; if I want change first slash, I writeo: var regexp = /\//; var_2 = stringa.replace(regexp, "zzz"); ok work and I have: zzzAAA/B/file.jpg;
7
by: VUNETdotUS | last post by:
How can I get the text after matching string is found: var str = "1111>AAAA<2222>BBBB<3333>CCCC"; if(str.indexOf("2222>")){ //how to get "BBBB" value following my "2222>" but before "<3333"...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.