473,399 Members | 3,401 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,399 software developers and data experts.

getting arguments withn RegEx please help

hi there,

I'm using RegEx object with the string "(\[.*?\])" to get arguments
from a line like this:

This line has got [one] argument and [another] one.

the issue is that I obtain a MathCollection with "[one]" and
"[another]".

how can I modify the pattern string to have [ and ] stripped so to get
"one" and "another"?

please help!
thank you.

--------

Francesco "Matro" Martire

available at www.realpopup.it:
RealPopup, the freeware winpopup replacer
RealAccount, freeware plugin for MS Outlook XP
MaTreo, freeware frontscreen for your Treo and PalmOS devices
Nov 15 '05 #1
3 2078
Hi,

You can do this with one match, like:

using System.Text.RegularExpressions;

Match m =
Regex.Match (strInput, "(?:.*?\\[(?'key'\\w*?)\\])*" );

// print all keys in string that are between [ ]
foreach (Capture c in m.Groups["key"].Captures)
{
System.Console.Write (c.ToString() + "\r\n" );
}

HTH
greetings
"matro" <ma***@despammed.com> wrote in message
news:ct********************************@4ax.com...
hi there,

I'm using RegEx object with the string "(\[.*?\])" to get arguments
from a line like this:

This line has got [one] argument and [another] one.

the issue is that I obtain a MathCollection with "[one]" and
"[another]".

how can I modify the pattern string to have [ and ] stripped so to get
"one" and "another"?

please help!
thank you.

--------

Francesco "Matro" Martire

available at www.realpopup.it:
RealPopup, the freeware winpopup replacer
RealAccount, freeware plugin for MS Outlook XP
MaTreo, freeware frontscreen for your Treo and PalmOS devices

Nov 15 '05 #2
Jhon already answered this but instead of writing out the code I thought you
should know what is happening here. First, you're getting "[one]" instead
of "one" because your parentheses are requesting the brackets. If your
regexp was "\[(.*?)\]" you'd trim that off.

Also, the "." matches any character except newline, so if you only want a-z,
you could use \w, otherwise you might match spaces between those brackets,
which may or may not be what you want.

The "?" at the end tells the regular expression to stop as soon as it can
and still match, so it won't match the right bracket as part of the "."
match.

I'm using RegEx object with the string "(\[.*?\])" to get arguments
from a line like this:

This line has got [one] argument and [another] one.

the issue is that I obtain a MathCollection with "[one]" and
"[another]".

how can I modify the pattern string to have [ and ] stripped so to get
"one" and "another"?

Nov 15 '05 #3
On Fri, 17 Oct 2003 15:29:40 -0400, "Mark Coffman" <mc******@kua.com>
wrote:
should know what is happening here. First, you're getting "[one]" instead
of "one" because your parentheses are requesting the brackets. If your
regexp was "\[(.*?)\]" you'd trim that off.


thank you both! this solved my issue. :-) thanks for explanations too,
really appreciated.

--------

Francesco "Matro" Martire

available at www.realpopup.it:
RealPopup, the freeware winpopup replacer
RealAccount, freeware plugin for MS Outlook XP
MaTreo, freeware frontscreen for your Treo and PalmOS devices
Nov 15 '05 #4

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

Similar topics

4
by: ivo welch | last post by:
I know regex can't do this, so may I ask what the recommended procedure is for extracting a bracketed TeX argument, which itself can contain other bracketed TeX arguments? $string = " text...
5
by: Yoshitha | last post by:
Hi I am working on a web project. I have a InstallerClass in my project. While making setup ( using web setup template) for this web application, I have added a userinterface with 4...
4
by: Garibaldi | last post by:
Folks, I'm having a bad regex day and can sure use your help, please.. I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
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 ...
2
by: ankit | last post by:
I want to get the start and end of all the patterns mattched in regex. I know I can get it with start() and end() fn of matched objects. But re.search() return the match object of first matching...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
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
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.