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

Regex and Match classes

I'm trying to grab everything between the square brackets
and this code just isn't working. I'm not sure what's going
on. I've tested the regular expression elsewhere and it works
as expected. Just not in my C# code...

Regex oRegex = new Regex( @"\[([\S\s]+)\]" );

string sSelectedItem = "[joe#bob!briggs@9]";

Match oMatch = oRegex.Match( sSelectedItem );

if( oMatch.Success ) {
MessageBox.Show( "Matched! Value is " + oMatch.Value );
sSelectedItem = oMatch.Value;

}
MessageBox.Show( "You just selected " + sSelectedItem );

What am I doing wrong?
Nov 16 '05 #1
1 1129
"Christoph Boget" <jc*****@yahoo.com> wrote:
I'm trying to grab everything between the square brackets
and this code just isn't working. [...]

Regex oRegex = new Regex( @"\[([\S\s]+)\]" );
string sSelectedItem = "[joe#bob!briggs@9]";
Match oMatch = oRegex.Match( sSelectedItem );


Is that your exact code? It works for me and produces the success
message.

Incidentally, instead of [\S\s] (meaning "any character that is or
isn't whitespace"), you could just use a single dot (meaning "any
character").

P.
Nov 16 '05 #2

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

Similar topics

1
by: Jeff Johnson [MVP: VB] | last post by:
Is there any way to retrieve the name of a capture group from the classes provided in the RegularExpressions namespace? GroupCollection implements ICollection and IEnumerable, not IDictionary, so...
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...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
3
by: Michael D Murphy | last post by:
Hi, I would like to know how to use Regular Expressions to iteratively return and print the items between the colons in the following string to say the console.. Any help would be appreciated....
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
6
by: Lubomir | last post by:
Hi, I am using the following pattern: "\\b" + MySttring + "\\b" If MyString is "one", this should pick up whole words like "one". The problem is, it will pick up also the word: "one.two"...
1
by: TumurS | last post by:
Hi! I need to parse an input string. The string must consist of 1, 2 or 3 float numbers separated with blanks: Regex r = new Regex(@"^\s*(?<x>+)(\s+(?<y>+)(\s+(?<z>+))*)*\s*$",...
7
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title ...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
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
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: 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
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
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
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.