Click here to Skip to main content
15,039,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Regex pattern(parent):([A-z]{1,})-([a-z]{1,})=>this pattern finds out(eg:mid-night).
Regex pattern (child):Need to Know regex pattern for finding words(midnight) and (mid night). I need Regex pattern for finding those format.

addtional information copied from non-answer below (after solution 1)
Thanks for your reply.
I am having a paragraph in word format(paragraph shown below)


We can’t answer that question until we know Ed’s objectives. If his aim is to fill all the seats without having to turn anyone away, $3 would be the best price to set. That’s the price at which the quantity of tickets demanded would equal the number of seats available in the auditorium. One possible objection to a $3 price, however, is that each film showing would lose money. Total costs would be $2,200, but total revenue would be only $2,100.we went outside at mid-nightThere was heavy rain at midnight.the last mid night was very cold.


the pattern you suggested finds ([A-z]{1,})([a-z]{1,}) all words which are combined,nut i need to get only the Midnight(all highlighted) word from the paragraph.similarly for space also i need to find that particular word alone using regex pattern.
please provide me a solution.

[edit2]missing bold added[/edit2]
Posted
Updated 9-Nov-13 1:26am
v3

Hi Bala,

For the word midnight: ([A-z]{1,})([a-z]{1,})
for the word mid might: ([A-z]{1,})\s([a-z]{1,}) or ([A-z]{1,}) ([a-z]{1,})
Its not a big deal right? ;-)

If you want to test or validate regex string refer this link[^]

Suggestion after updating the question

You need to get words on Word basis not on regex pattern basis,am right? to explain clear If you have another word mid-day in that paragraph which has similar pattern to mid-night, then that word also retrieved if you use regex pattern... do I make sense here?

Is that what you want?

Updated solution:

Works for all except white space right? little bit overhead,but do-able...
for the above requirement if you select midnight,then
put is as compare string with whole passage.if the right side of the string has any special character like('space','-')then replace the string with empty character('') and compare with the word 'midnight' if it matches then highlight that word if its not then move on to another word...
Refer this link[^] for your reference

And you can refer this link [^]also, it gives you direct solution I believe.....

Have fun.....

Hope this helps you a bit.

Regards,
RK
   
v8
Comments
Nelek 9-Nov-13 7:27am
   
OP answered you in a "solution" I copied the new info to the question. Please have a look.
♥…ЯҠ…♥ 9-Nov-13 7:45am
   
updated my solution according to your question.....
Member 10391350 10-Nov-13 3:16am
   
Yes i need that another word as you said mid-day also need to be found from that passage.For that only i need a pattern dynamically.(to get Mid-day,mid day,midday) and so many words(to-night,tonight,to night) etc like this.
Member 10391350 10-Nov-13 2:25am
   
Hi,
I understand that your pattern matches for all the words which have spaces but i need a pattern for hphenated words(mid-night).i consider this as a parent. I need pattern for (mid night and midnight) from a passage.so your solution gives all the words with spaces also.I need a pattern for hyphen words which are seperated by spaces and joined.
♥…ЯҠ…♥ 10-Nov-13 23:00pm
   
Works for all except white space right? little bit overhead,but do-able...for the above requirement if you select midnight, then compare with whole passage... take this link as reference http://bytes.com/topic/c-sharp/answers/938250-how-compare-2-strings-word-document-special-character
Thanks for your reply.
I am having a paragraph in word format(paragraph shown below)


We can’t answer that question until we know Ed’s objectives. If his aim is to fill all the seats without having to turn anyone away, $3 would be the best price to set. That’s the price at which the quantity of tickets demanded would equal the number of seats available in the auditorium. One possible objection to a $3 price, however, is that each film showing would lose money. Total costs would be $2,200, but total revenue would be only $2,100.we went outside at mid-nightThere was heavy rain at midnight.the last mid night was very cold.


the pattern you suggested finds ([A-z]{1,})([a-z]{1,}) all words which are combined,nut i need to get only the Midnight(all highlighted) word from the paragraph.similarly for space also i need to find that particular word alone using regex pattern.
please provide me a solution.
   
Comments
Nelek 9-Nov-13 7:24am
   
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional question.
Nelek 9-Nov-13 7:51am
   
rk_prabakar has updated the answer after your new information. Please try it and if you want to continue asking him, use the comments as I have done with you and with him. At best start with a new comment thread, it will be easier to follow the different conversations.
Hi
In two following links you can find solutions that may match your need.

http://msdn.microsoft.com

www. stackoverflow.com


best regards
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900