Click here to Skip to main content
15,886,689 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 am having a passage with a group of words. In that passage (mid-night,mid night,midnight)these words are present, i need an regex pattern to match these words from passage.
please provide me a solution.
Posted
Comments
BillWoodruff 10-Nov-13 7:53am    
As OriginalGriff said in his thoughtful answer: "What are you actually trying to achieve" ? What do you want to do based on finding the occurrences ?

What (if anything) do you need to generate from your solution: a list of the indexes of the starting points of the first term, and a list of the starting points of the second term ?

Is it okay to "destroy" the original string whlie you process it ?

1 solution

I'm not sure that a regex is exactly what you are looking for here: it isn't a text matching process, it's a pattern matching process. It can't tell the difference between:
mid night

and
midnight tonight
They are both "a word" followed by "a space", followed by "a word".

But if you want to find
word-otherword
with your first regex and then search for all occurrences of any of
word-otherword
word otherword
wordotherword
then each one will need you to create a separate regex along the lines of:
word[\s-]{0,1}otherword
and run that for each pair of match groups in your original regex results.
 
Share this answer
 
Comments
Member 10391350 10-Nov-13 3:13am    
I am Not looking for a particular word.I need that pattern dynamically to find hyphenated words and those words with spaces and combined also.I have a passage from that i need to use regex pattern to find the words dynamically.
OriginalGriff 10-Nov-13 3:32am    
Then a regex is not what you want: as I said, a regex can't tell the difference between "mid night" and "midnight tonight".
If you want a generic word pickup, then you are going to probably need a dictionary of actual words and look for each of them...

What are you actually trying to achieve - there may be a better solution.
BillWoodruff 10-Nov-13 7:53am    
+5

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