473,387 Members | 3,801 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.

More regex questions

Hi everyone,
I'm developing some code that will hopefully match one of the strings
stored in an array:

String [] attrTypes = {"/SCEQUIPMENT/", "/SCOINSTRUMENT/", "/SCPLIN/",
"/SCHVAC/", "/SCCAB/", "^(/EQUIPMENT/)", "/PIPE/", "^(/HVAC/)"};

for (int i=0; i<8; i++)
{
Match m = Regex.Match( args[0].ToString(), attrTypes[i] );
// args[0] is an input string and contains (eg)
"SCEQUIPMENT (unfiltered)" etc.

if (m.Success)
{

but I never reach any of the code after m.Success. Can anyone please
suggest a solution?

TIA

Trev

Dec 6 '06 #1
4 1111
Hello Trev,
>I'm developing some code that will hopefully match one of the strings
stored in an array:
<snip>

The major problem here is that you seem to have copied the regular
expressions from Perl... the /.../ syntax is common there, for a variety
of reasons, but is not needed in C# (or .NET, for that matter). Get rid of
all the / characters in your expressions and you should see something
happening.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 6 '06 #2

Oliver Sturm wrote:
Hello Trev,
I'm developing some code that will hopefully match one of the strings
stored in an array:

<snip>

The major problem here is that you seem to have copied the regular
expressions from Perl... the /.../ syntax is common there, for a variety
of reasons, but is not needed in C# (or .NET, for that matter). Get rid of
all the / characters in your expressions and you should see something
happening.

Thanks for your help Oliver, I really appreciate it (sorry I haven't
replied sooner, I have been on vacation): I admit that I started using
regex with Perl so the syntax must have stuck in my mind.

Just one more question: how do I only match to words at the start of a
line? So that
"EQUIPMENT" will only match with "EQUIPMENT (unfiltered)" but not
"GASKET for EQUIPMENT", "SCEQUIPMENT (unfiltered)" or "GASKET for
SCEQUIPMENT"

- I'm finding that a match is done anywhere in the string, but I can't
figure out how to just match at the start!

TIA

Trev

Dec 14 '06 #3
Hello Trev,
>Just one more question: how do I only match to words at the start of a
line? So that
"EQUIPMENT" will only match with "EQUIPMENT (unfiltered)" but not
"GASKET for EQUIPMENT", "SCEQUIPMENT (unfiltered)" or "GASKET for
SCEQUIPMENT"
Use ^EQUIPMENT to match only at the start of the line (or the string,
rather).
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 14 '06 #4
On Thu, 14 Dec 2006 13:34:13 +0000, Oliver Sturm wrote:
>
Use ^EQUIPMENT to match only at the start of the line (or the string,
rather).

Oliver Sturm
And be sure to set the appropriate regex option. Given

EQUIPMENT
EQUIPMENT

If your regex option includes RegexOptions.Multiline it will match twice.
Otherwise it will match only once

--
Bits.Bytes
http://bytes.thinkersroom.com
Dec 15 '06 #5

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

Similar topics

1
by: rdimayuga | last post by:
I need a regex pattern that will match a string starting with zero or one dot's. For example, ".string" and "string" should both match, but something like "estring" should not match. So far, I've...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
8
by: Just Me | last post by:
I want to use regular expressions to search a string, give the user the option of replacing, and then maybe replacing the data - using reg expressions for the search and the replace strings. ...
13
by: O-('' Q) | last post by:
In my effort to fully understand how to use the RegExp engine in c#.net (VS2005), I have begun to tinker with it more since I was shown about the ability the other day in a lengthy newsgroup...
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...
1
by: Dan Holmes | last post by:
i have this: new System.Text.RegularExpressions.Regex("^\d+$") // \d by itself failed as well. but the compiler generates "unrecognized escape sequence". so i changed it to this: new...
3
by: jwgoerlich | last post by:
Hello group, I am working on a query string class. The purpose is to parse name-value pairs from incoming text. Currently, I am using the Regex code below. I have two questions. First, the...
8
by: Trev | last post by:
Hi, If I had a string denoted by MyArray, how would I extract the number in brackets for use in the programme later on? I've tried "\" but all I get is a syntax error. What would be the usage for...
2
by: Shawn B. | last post by:
Greetings, Lets say I have the following expression: (<A|ABBR|ADDRESS|APPLET(\s){1,}(.*?)>(.*?)</A|ABBR|ADDRESS|APPLET) Such that it'll match any HTML tag that opens with the above specified...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.