473,657 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Regex

Hello,

I am trying to create a Regex object which can match ASCII character
0x05 in a given string. I have written following code to accomplish
this:

System.Text.Reg ularExpressions .Regex regex = new
System.Text.Reg ularExpressions .Regex("[\\x05]*?",
System.Text.Reg ularExpressions .RegexOptions.C ompiled);

Now when I try to do like this:

regex.Matches(s tr);

It gives me an array of Match objects of length equal to the length of
the string. Even if the ASCII character is not present in the string.
Can anyone tell what am I getting wrong here?

Regards

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

Jul 7 '07 #1
5 1647
maybe you should use [\\x05]+, i guess
Jul 7 '07 #2
Hello Jason,

Thanks for the help.

Regards,
Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

On Jul 7, 12:53 pm, "Jason" <ydong.pub...@g mail.comwrote:
maybe you should use [\\x05]+, i guess

Jul 7 '07 #3
* Maqsood Ahmed wrote, On 7-7-2007 7:29:
Hello,

I am trying to create a Regex object which can match ASCII character
0x05 in a given string. I have written following code to accomplish
this:

System.Text.Reg ularExpressions .Regex regex = new
System.Text.Reg ularExpressions .Regex("[\\x05]*?",
System.Text.Reg ularExpressions .RegexOptions.C ompiled);

Now when I try to do like this:

regex.Matches(s tr);

It gives me an array of Match objects of length equal to the length of
the string. Even if the ASCII character is not present in the string.
Can anyone tell what am I getting wrong here?

Regards

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

The * makes the whole regular expression optional. So at every character
in the string it matches nothing, but nothing, according to this
expression, is a match.

This expression should do the trick:

@"\x05"

Or if you want them grouped together if there is more than one instance
of \x05 you can use

@"\x05+"

I'm not sure what you're trying to accomplish, Regex is a very expensive
technique for finding an instance of a certain character in a string. A
Simple string.IndexOf should accomplish the same result, but much, much
faster.

Jesse

Jul 7 '07 #4
You are welcome
Jul 7 '07 #5
On Jul 7, 6:42 pm, Jesse Houwing <jesse.houw...@ nospam-sogeti.nl>
wrote:
* Maqsood Ahmed wrote, On 7-7-2007 7:29:


Hello,
I am trying to create a Regex object which can match ASCII character
0x05 in a given string. I have written following code to accomplish
this:
System.Text.Reg ularExpressions .Regex regex = new
System.Text.Reg ularExpressions .Regex("[\\x05]*?",
System.Text.Reg ularExpressions .RegexOptions.C ompiled);
Now when I try to do like this:
regex.Matches(s tr);
It gives me an array of Match objects of length equal to the length of
the string. Even if the ASCII character is not present in the string.
Can anyone tell what am I getting wrong here?
Regards
Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

The * makes the whole regular expression optional. So at every character
in the string it matches nothing, but nothing, according to this
expression, is a match.

This expression should do the trick:

@"\x05"

Or if you want them grouped together if there is more than one instance
of \x05 you can use

@"\x05+"

I'm not sure what you're trying to accomplish, Regex is a very expensive
technique for finding an instance of a certain character in a string. A
Simple string.IndexOf should accomplish the same result, but much, much
faster.

Jesse- Hide quoted text -

- Show quoted text -
Yes Jesse, you are right, it was an expensive operation, I have done
it using string class.
Thanks for your help.

Regards,

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

Jul 11 '07 #6

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

Similar topics

6
2048
by: Tony C | last post by:
I'm writing a python program which uses regular expressions, but I'm totally new to regexps. I've got Kuchling's "Regexp HOWTO", "Mastering Regular Expresions" by Oreilly, and have access to online stuff too. But I would like to find a mailing list or newsgroup where I can ask questions about regexps (when things don't work), not specifically dealing with Python. When I have Python-regexp questions, I'll post them here of course.
8
5578
by: Bibe | last post by:
I've been trying to get this going for awhile now, and need help. I've done a regex object, and when I use IsMatch, it's behavior is quite weird. I am trying to use Regex to make sure that a variable is only alphanumeric (no strange characters). Here's the code: Regex regExp = new Regex("*");
4
1513
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match on every word ? For example : String myString =" This is the string that stupid H can't split up"; // A good RegEx needed here .. So the result would look something like this ;
6
4789
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 string. It's actually the input string into a Microsoft Index Server search. The string will consist of words, perhaps enclosed in quotes or parentheses. I'd like to use Regex to pull out the words, or the phrases if the words are enclosed in quotes....
4
3142
by: henrik | last post by:
Hi I have a regex question. I want to find all content of a <td class="someclass"> tag. This means the expression should include all other tags included between <td class="someclass"> and </td>. Please help Regards
9
2079
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 lot of times here.... Requirement: ------------------- I want to get the value of "href" i.e "city1.html" by searching "city1" between the <a</atag. Please note that "city1" can repeat lot of
2
2362
by: Alex Maghen | last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone really good with Regular Expressions can help me out here. I need to write a regular expression that will do the following: Search a whole blob of text (including newlines and everything). Find any text enclosed in brackets (), and replace it with a string I provide and then concatenate the text that had been enclosed in the brakets, without the brakets.
3
4871
by: =?Utf-8?B?TmF2ZWVu?= | last post by:
Not sure if this is the right forum for this question but couldn'd find another newsgroup. I am new to Regular expressions and would like help in deciding which pattern allows me to split a string into sets of words based on capital letter. For e.g. if i have a string "FirstnameLastname" I would like the result to return me Firstname and Lastname. The other conditions of the input string are 1) If whitespace exists, do not return a...
10
1567
by: supercrossking | last post by:
I am trying to the values of string of text in the sample before. The ds are for digits and s is for string and string of text is for a string with more than one or two values. I am trying to use regex and the .groups method. Please help. d|d|d|string of text 1||s|s|||dd.dd|ss|string of text 2||||||||||||||||||||||||||string of text 2 I only want string of text1
0
1622
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with an '@'in the filename on the assumption it's already in the correct format. Uncomment the os.rename line
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.