Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,





HyderabadProduct Development, Design his own designs and developed the websites. Framework: Magento: Drupal, Joomla, Ruby on Rails , Codeigniter (any one or a combination). Good in Sql Database. Looking.





From the above text i want to capture data only Hyderabad i.e, i want to remove the text when second capital appears using regular expression
Posted

C#
Regex regex = new Regex(@"^(?<part>[A-Z][a-z]+)[A-Z]");

Match m = regex.Match(@"HyderabadProduct Development, Design his own designs and developed the websites. Framework: Magento: Drupal, Joomla, Ruby on Rails , Codeigniter (any one or a combination). Good in Sql Database. Looking.");

if (m.Success)
{
   string wantedPart = m.Groups["part"].Value;
}
 
Share this answer
 
v2
Comments
Member 10226004 11-Jul-14 9:12am    
Hi George
Thanks for the reply,

I am actually using a third party tool to capture the data - i don't have an option change the coding but can simple apply a small regular expression to retrieve the data. I have tried with the following expression .*(?=[A-Z]{1,2}) but this was removing the last word - Looking.
It will be awesome if you could suggest an expression in the same manner to retrieve only the word Hyderabad - [Text before the second capital letter]
George Jonsson 11-Jul-14 9:47am    
I just did.
Try the code.
If all are alphabets only before the 2nd capital:
(?=(^[A-Z][a-z]*))
 
Share this answer
 
Comments
Member 10226004 11-Jul-14 10:17am    
PHP Developer, 1 Yrs
Company:Eminent Solution
Location:HyderabadProduct Development, Design his own designs and developed the websites. Framework: Magento: Drupal, Joomla, Ruby on Rails , Codeigniter (any one or a combination). Good in Sql Database. Looking.


I am able to get it right but earlier i used this expression to separate the location first
with the text before it using this expression (?<=Location:).* But now when i combine both it is not working for me. Can you suggest another alternative

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