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

regexp question

Hey all,

I'm trying to do a regexp that will gracefully extract the fields (fn)
from a string in this format:

(f1, f2, f3),(f1, f2, f3),(f1, f2, f3),...,(f1, f2, f3)

Is there a way I could grab each (f1, f2, f3) and then iterate through
them gracefully. I'm using Split(str, ",\)") , but then I have to remove
the ('s and )'s from the beginning and end of the first and last () set.
It's not a big deal, it's just ugly.

Can't I do a regexp like "\(.*\)", and iterate through every match in a
string of indeterminate length?

Thanks,

Eric
Nov 18 '05 #1
2 1106
"Eric Gibson" <ai*****@comcast.net> wrote in
news:1s_cd.273032$D%.209883@attbi_s51:
Hey all,

I'm trying to do a regexp that will gracefully extract the
fields (fn)
from a string in this format:

(f1, f2, f3),(f1, f2, f3),(f1, f2, f3),...,(f1, f2, f3)

Is there a way I could grab each (f1, f2, f3) and then
iterate through
them gracefully. I'm using Split(str, ",\)") , but then I have
to remove the ('s and )'s from the beginning and end of the
first and last () set. It's not a big deal, it's just ugly.

Can't I do a regexp like "\(.*\)", and iterate through every
match in a
string of indeterminate length?


Eric,

Yes you can. Use \((?<content>.*?)\) to get 1-N capture groups named
"content". Each group will contain f1, f2, f3 (without the
parentheses).

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 18 '05 #2
Chris R. Timmons wrote:

[snip]

Yes you can. Use \((?<content>.*?)\) to get 1-N capture groups named
"content". Each group will contain f1, f2, f3 (without the
parentheses).


Perfect, I eventually came up with (well, sort of) this:
Dim inputStr As String = "(f1, f2, f3), (f4, f5, f6)"
Dim inputStrFlds As String()
Dim msg As String

Dim Regexp as Regex = New Regex("\((?<content>.*,.*,.*?)\)",
RegexOptions.IgnoreCase)
Dim objMatch as Match

If inputStr.Length > 0 Then

'Create a Match object instance / iterate through the MatchCollection

For Each objMatch in Regexp.Matches(inputStr)

inputStrFlds = Split(objMatch.Groups("content").Value, ",")
If UBound(inputStrFlds) <> 0 Then
Response.Write(inputStrFlds(0) & " and " & inputStrFlds(1) & _
" and " & invalidFlds(2) & "<br>")
End If
Next

End If

Thanks!

Eric
Nov 18 '05 #3

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

Similar topics

1
by: python_charmer2000 | last post by:
I want to match several regexps against a large body of text. What I have so far is similar to this: re1 = <some regexp> re2 = <some regexp> re3 = <some regexp> big_re = re.compile(re1 +...
19
by: Magnus Lie Hetland | last post by:
I'm working on a project (Atox) where I need to match quite a few regular expressions (several hundred) in reasonably large text files. I've found that this can easily get rather slow. (There are...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
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...
3
by: Sped Erstad | last post by:
There must be a simple regexp reason for this little question but it's driving me nuts. Below is a simple regexp to determine if a string contains only numbers. I'm running these two strings...
2
by: Bill McCormick | last post by:
Hello, I'm new to VB.NET but have used regexp in Perl and VI. I'd like to read a regular expression from a file and apply it to a string read from another file. The regexp is simple word...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
7
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
8
by: Darryl Kerkeslager | last post by:
Currently I am using the RegExp object to parse a large dataset in an Access table - but this table was exported from SQL Server, and the very correct question was asked - why not just do it in SQL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.