473,387 Members | 1,493 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.

Need a regex for this...

I'm trying to learn regex but since I've spent way too much time on the
following "simple" case, there's obviously something I'm missing. I need to
find all occurrences of a specific non-whitespace character sequence in a
string, but only if it occurs somewhere within a set of parentheses and only
if it's a whole word. Assuming the sequence to be found is the word "the"
and the string to be searched is as follows, the only matches should be in
the last 4 cases (where whitespace may or may not occur after any opening
parenthesis and/or before any closing parenthesis:

the these (there) (the) (now is the) (the time) (now is the time) etc.

As you can see, if the whole word "the" is part of a larger string within
parentheses, it will have whitespace on one or both sides of it. But if it
is the only word, it may or may not. I know I can search for the whole word
anywhere in the string by using the regex \bthe\b but it's the parentheses
that are causing me the problems. I've tried all kinds of combinations that
I won't bore you with but obviously none have been completely correct.

And two more things... I've got both "RegexBuddy" and "Rad Software Regular
Expression Designer 1.4", which I've been using to help me wade through all
this. Do any of you have any other tools you would recommend for this
purpose, or a preference between these two? Also, does anyone know of a tool
that would allow me to state what I would like to achieve as an English
sentence, and would then produce a regex for it? (I know, keep dreaming! :-))

Thanks
Ray

Oct 14 '07 #1
3 2389


Ray Mitchell wrote:
I'm trying to learn regex but since I've spent way too much time on the
following "simple" case, there's obviously something I'm missing. I need to
find all occurrences of a specific non-whitespace character sequence in a
string, but only if it occurs somewhere within a set of parentheses and only
if it's a whole word. Assuming the sequence to be found is the word "the"
and the string to be searched is as follows, the only matches should be in
the last 4 cases (where whitespace may or may not occur after any opening
parenthesis and/or before any closing parenthesis:

the these (there) (the) (now is the) (the time) (now is the time) etc.

As you can see, if the whole word "the" is part of a larger string within
parentheses, it will have whitespace on one or both sides of it. But if it
is the only word, it may or may not. I know I can search for the whole word
anywhere in the string by using the regex \bthe\b but it's the parentheses
that are causing me the problems. I've tried all kinds of combinations that
I won't bore you with but obviously none have been completely correct.
Did you try this:
\(([^)]*\bthe\b.*?\)
And two more things... I've got both "RegexBuddy" and "Rad Software Regular
Expression Designer 1.4", which I've been using to help me wade through all
this. Do any of you have any other tools you would recommend for this
purpose, or a preference between these two? Also, does anyone know of a tool
I'm using RegexTester, which can be downloaded from:
http://www.unibetter.com/deerchao/do...egexTester.zip
It's very light weight, and uses .Net Regex Engieen, and that's all
the reason why I use it.
that would allow me to state what I would like to achieve as an English
sentence, and would then produce a regex for it? (I know, keep dreaming! :-))

Thanks
Ray
So I guess you do know that's a dream :)
I think RegexBuddy is one of the closest tools to that dream.

Oct 14 '07 #2


"deerchao" wrote:
>

Ray Mitchell wrote:
I'm trying to learn regex but since I've spent way too much time on the
following "simple" case, there's obviously something I'm missing. I need to
find all occurrences of a specific non-whitespace character sequence in a
string, but only if it occurs somewhere within a set of parentheses and only
if it's a whole word. Assuming the sequence to be found is the word "the"
and the string to be searched is as follows, the only matches should be in
the last 4 cases (where whitespace may or may not occur after any opening
parenthesis and/or before any closing parenthesis:

the these (there) (the) (now is the) (the time) (now is the time) etc.

As you can see, if the whole word "the" is part of a larger string within
parentheses, it will have whitespace on one or both sides of it. But if it
is the only word, it may or may not. I know I can search for the whole word
anywhere in the string by using the regex \bthe\b but it's the parentheses
that are causing me the problems. I've tried all kinds of combinations that
I won't bore you with but obviously none have been completely correct.

Did you try this:
\(([^)]*\bthe\b.*?\)
And two more things... I've got both "RegexBuddy" and "Rad Software Regular
Expression Designer 1.4", which I've been using to help me wade through all
this. Do any of you have any other tools you would recommend for this
purpose, or a preference between these two? Also, does anyone know of a tool

I'm using RegexTester, which can be downloaded from:
http://www.unibetter.com/deerchao/do...egexTester.zip
It's very light weight, and uses .Net Regex Engieen, and that's all
the reason why I use it.
that would allow me to state what I would like to achieve as an English
sentence, and would then produce a regex for it? (I know, keep dreaming! :-))

Thanks
Ray

So I guess you do know that's a dream :)
I think RegexBuddy is one of the closest tools to that dream.

deerchao,

Yup, that's it. It was the lack of the question mark that was my problem.
Obviously I need to learn a little bit more about "greedy" v.s. "stingy", and
to think of how much time I wasted on this! Thanks for your help!

Ray
Oct 14 '07 #3
On Oct 14, 12:43 am, Ray Mitchell
<RayMitchell_NOSP...@MeanOldTeacher.comwrote:
And two more things... I've got both "RegexBuddy" and "Rad Software Regular
Expression Designer 1.4", which I've been using to help me wade through all
this. Do any of you have any other tools you would recommend for this
purpose, or a preference between these two?
I love Expresso.

Oct 14 '07 #4

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

Similar topics

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...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
1
by: hillcountry74 | last post by:
Hi, I'm stuck with this regular expression from past 2 days. Desperately need help. I need a regular expression that will allow all characters except these *:~<>' This is my code in...
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: Extremest | last post by:
I have a huge regex setup going on. If I don't do each one by itself instead of all in one it won't work for. Also would like to know if there is a faster way tried to use string.replace with all...
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...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
0
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or rewrite them without Regex? The most time-consuming...
4
by: Danny Ni | last post by:
Hi, The following code snippet is causing CPU to max out on my local machine and production servers. It looks fine on Expresso though. Regex rgxVideo = new...
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: 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: 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?
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
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.