473,405 Members | 2,262 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,405 software developers and data experts.

regexp in .net

Hi All,
Im trying to parse a file to find all occurance of strings inside
square brackets eg: "[item] kllkj ljlj ljlj [item 1] ljl [item 2]"
would return "item,item 1,item 2".

To me this seemed like this type of problem was made for regexp.

But i havent done regexp for years, and i need some good site or
pointers to example regexp code in c# but i cant many example out on
google. :o(

my regexp so far only find one occurance "[item]" using
'\[[a-z\.]+\b+\]'.

To me this stuff in mind boggleing, does anyone have a good site or a
good mind for this.

Thanks
slyi

Nov 17 '05 #1
4 1383
ad******@gmail.com wrote:
Im trying to parse a file to find all occurance of strings inside
square brackets eg: "[item] kllkj ljlj ljlj [item 1] ljl [item 2]"
would return "item,item 1,item 2".

To me this seemed like this type of problem was made for regexp.

But i havent done regexp for years, and i need some good site or
pointers to example regexp code in c# but i cant many example out on
google. :o(

my regexp so far only find one occurance "[item]" using
'\[[a-z\.]+\b+\]'.


The expression \[[^\]]*\] will match all strings in brackets, by returning
multiple matches. If you'd rather have a single match with multiple
captures, you'd need to use (\[[^\]]*\])* instead.

Testing for multiple captures may be faster - I have once written a blog
article about this distinction:
http://www.sturmnet.org/blog/archive...ches-captures/

Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2
Thank that was exactly what i need.
Could you recommend any good sites / tutorials for regexp as its an
area im poor at and would like to improve on?

Nov 17 '05 #3
ad******@gmail.com wrote:
Thank that was exactly what i need.
Could you recommend any good sites / tutorials for regexp as its an
area im poor at and would like to improve on?


Sorry, I can't recommend anything specific. I learnt it all a long time
ago from documentation and examples of Unix sed and Perl, which I think
are quite good - but many of their samples are for sed and Perl,
obviously, which doesn't make them a very good resource for somebody
wanting to use regular expressions in .NET. Two nice (and short) primers
are here: http://www.developer.com/lang/article.php/3330231 and here:
http://www.futureone.com/~sponge/tut...xOverview.html , but
this is really basic stuff. This is a good book, but it also uses Perl as
the programming language around the regular expressions:
http://www.oreilly.com/catalog/regex/

When you are becoming a little better with regexes, it's probably best if
you set yourself some tasks and try to ask about the details - or compare
your results to published resources like http://www.regexlib.com/

Finally, of course, for the exact detailed definition of regular
expressions in .NET, you should use the MSDN pages:
http://msdn.microsoft.com/library/de...xpressions.asp
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #4
Thanks i always feel im missing out on a powerful tool, understanting
even basic regexp can a huge help for text processing.

Nov 17 '05 #5

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:...
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....
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...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
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...
4
by: conan | last post by:
This regexp '<widget class=".*" id=".*">' works well with 'grep' for matching lines of the kind <widget class="GtkWindow" id="window1"> on a XML .glade file However that's not true for the...
6
by: runsun pan | last post by:
Hi I am wondering why I couldn't get what I want in the following 3 cases of re: (A) var p=/(+-?+):(+)/g p.exec("style='font-size:12'") -- // expected
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.