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

Stupid regex help

Happy new years everybody!
Alright, I've got a string, with this as an example:

Title: The title of something

Title may or may not be followed with a colon (:), dash (-), or a
space-dash ( -)
I need to extract "The title of something". Here's what I got so far:

^(Title)[:\- ]|( \-)

which, I think, will match all possible varieties that I need. But
how do I extract whatever is to the right of it?

Thanks,
Austin Ehlers
Nov 15 '05 #1
4 1297
If you use this... (?<=(Title))([\:|-]\s*)(.*) the third group will
contain the text you want. I used the "." assuming that your text in the
title could include any character other than a new line. I think it should
probably have a $ at the end to demark the end of the line but I'm not sure
how your string is coming in.

HTH,

Bill
"Austin Ehlers" <th***********************@hotmail.com> wrote in message
news:ps********************************@4ax.com...
Happy new years everybody!
Alright, I've got a string, with this as an example:

Title: The title of something

Title may or may not be followed with a colon (:), dash (-), or a
space-dash ( -)
I need to extract "The title of something". Here's what I got so far:

^(Title)[:\- ]|( \-)

which, I think, will match all possible varieties that I need. But
how do I extract whatever is to the right of it?

Thanks,
Austin Ehlers

Nov 15 '05 #2
Jax
If there are only three options those being (:/-/ -)
Then this might be the solution;

foreach(string myString in myCollectionOfTheseStrings)
{
int charCtr = 0;
char prevChar = '';
string begin = "";
string end = "";
foreach(char c in myString)
{
if(c == ':')
{
begin = myString.Substring(0,charCtr);
int cutPoint = charCtr+1;
end = myString.Substring(cutPoint, myString.Length -
cutPoint);
break;
}
else if(c == '-')
{
if(prevChar == '')
{
begin = myString.Substring(0,charCtr-1);
int cutPoint = charCtr+1;
end = myString.Substring(cutPoint, myString.Length -
cutPoint);
break;
}
else
{
begin = myString.Substring(0,charCtr);
int cutPoint = charCtr+1;
end = myString.Substring(cutPoint, myString.Length -
cutPoint);
break;
}
}
charCtr++;
prevChar = c;
}
// Do something with string begin and string end here
}

Of course this is presuming that none of the titles have
a ':' or '-' within the name, if that is the case my
solution sucks and you should ignore me.

Hope that helps
jax
Nov 15 '05 #3
Hello!

If you're supposed to do a simple string op, like checking for an ending
char, why not use the string.EndsWith() method? If this isn't what you're
looking for, let me know and I'll help you out with the RegEx (although your
posting was a little hard to understand).

--
venlig hilsen / with regards
anders borum
--
Nov 15 '05 #4
Unfortunately, it looks like there will be many more diff.
combinations than I thought. For those that match my pattern, this
works:
(?<=(Title))((: )|( \- )|( )|(\-)|(\- ))(.*)+?$
and the last group.

Thanks for all the help everyone,
Austin

On Sun, 4 Jan 2004 16:30:43 -0500, "William Ryan"
<do********@nospam.comcast.net> wrote:
If you use this... (?<=(Title))([\:|-]\s*)(.*) the third group will
contain the text you want. I used the "." assuming that your text in the
title could include any character other than a new line. I think it should
probably have a $ at the end to demark the end of the line but I'm not sure
how your string is coming in.

HTH,

Bill
"Austin Ehlers" <th***********************@hotmail.com> wrote in message
news:ps********************************@4ax.com.. .
Happy new years everybody!
Alright, I've got a string, with this as an example:

Title: The title of something

Title may or may not be followed with a colon (:), dash (-), or a
space-dash ( -)
I need to extract "The title of something". Here's what I got so far:

^(Title)[:\- ]|( \-)

which, I think, will match all possible varieties that I need. But
how do I extract whatever is to the right of it?

Thanks,
Austin Ehlers


Nov 15 '05 #5

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

Similar topics

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 ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
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...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
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...
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: 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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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: 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:
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...

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.