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

Regular Expression:Searching for a match within an arbitrary parag

Hello All,
i have been cracking my skull on how to seach a particular reg exp match
within a string? it does not seem to happen except the whole arbitrary string
is the exact match of the regular expression specified....but the question is
how do i search for and get all or a number of specified matches within an
arbitrary long string. e.g

for example this is my reg exp i am using:

@"^-[A-Z][a-z]*-$" which will match any string within two full-stops "-"
and"-" example being :
-Cat-

but now how do i search and retreive that match and any other matches from
within a very long string such as:

this is a very long and pointless sentence where i am trying to
retreive-Cat-then -Dog-also something further along this overbearing sentence
at say this point -Man-.

hence retreive -Cat- , -Dog- and -Man-

Can this be done followed by an example please ?

because at the moment i can only match a match if the whole string is a
match! e.g if the whole string i want to find my match from is a match such
as "-Cat-" and that is not what i want i want to get a match or more matches
from a whole load of text...
geez this is giving me a headache just writing this as well!

thanks in advance..
--
The Matrix Insurrection
Nov 16 '05 #1
2 1873
ShadowOfTheBeast wrote:
for example this is my reg exp i am using:

@"^-[A-Z][a-z]*-$" which will match any string within two full-stops "-"
and"-" example being :

because at the moment i can only match a match if the whole string is a
match! e.g if the whole string i want to find my match from is a match
such as "-Cat-" and that is not what i want i want to get a match or more
matches from a whole load of text...
geez this is giving me a headache just writing this as well!


Your regexp is wrong if you want to do that. Remove the ^ at the beginning
and the $ at the end. They mean "start of text" and "end of text".. so this
regexp only matches if the first and last chars in your text are a "-".

hth,
Max

Nov 16 '05 #2
Thanks Max, i appreciate it i will try it now

"Markus Stoeger" wrote:
ShadowOfTheBeast wrote:
for example this is my reg exp i am using:

@"^-[A-Z][a-z]*-$" which will match any string within two full-stops "-"
and"-" example being :

because at the moment i can only match a match if the whole string is a
match! e.g if the whole string i want to find my match from is a match
such as "-Cat-" and that is not what i want i want to get a match or more
matches from a whole load of text...
geez this is giving me a headache just writing this as well!


Your regexp is wrong if you want to do that. Remove the ^ at the beginning
and the $ at the end. They mean "start of text" and "end of text".. so this
regexp only matches if the first and last chars in your text are a "-".

hth,
Max

Nov 16 '05 #3

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

Similar topics

4
by: ajikoe | last post by:
Hello, For example I have a string : "Halo by by by" Then I want to take and know the possition of every "by" how can I do it in python? I tried to use: p = re.compile(r"by") m =...
3
by: Bill Willyerd | last post by:
Is it possible? I have a request to create a stored proc that will dynamically add a range to a WHERE clause based on a numeric value of a comment type. If the incoming comment type request is...
3
by: Derek Stone | last post by:
In my continuing inability to completely understand regular expressions I have a new one for you. I'd like to capture a string "A" unless it is anywhere in between string "B" and string "C". ...
4
by: aliensite | last post by:
My code is too greedy, how can it be fixed? Here is my code: Desired output - First:,Second:,Third: <br> <script type="text/javascript"> var regEx = /*?:/g; var html = "<br>First:ratio<br...
4
by: Johnny Lee | last post by:
Hi, I've met a problem in match a regular expression in python. Hope any of you could help me. Here are the details: I have many tags like this: xxx<a href="http://xxx.xxx.xxx" xxx>xxx xxx<a...
5
by: Paul Johnston | last post by:
Hi Just started using c# to do a task I usually use Perl to do and hit a limit in my knowledge :-) I have a program which reads from a large text file, extracts certain lines then gets a string...
17
by: Randy Webb | last post by:
I know that the /g flag will match all occurrences. Is there a way, with a Regular Expression, to match all occurrences *except* the last one? pattern = /df/g; var myString = "asdfasdfasdfasdf";...
2
by: teo | last post by:
match word with interpunctuation Hallo, I need to build a regular expression able to match a specified word, preceded and followed by few chars (mainly interpunctuation) Below the code. ...
6
Markus
by: Markus | last post by:
I'm asking the question for once! Say I have the expression @@ that matches anything other than the characters specified. I also want spaces to be allows, including \n, \t, etc. I've tried adding...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
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
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...

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.