Find string inside of string
|
|||
|
Rank: ? (3)
Member #: 26980 |
Hi, a was wondering how i could find a case-sensitive string inside of another string. But the case-sensitive string is not known. ...
Find a 7 character string, but string is made up of A-Z A-Z A-Z a-z A-Z A-Z A-Z. So the string is made up 3 capital characters A-Z, 1 lowercase character, and then 3 capitol characters. Example runverUNCunruynXGTyERQvbrBNURBNIBuirRGRGRntuvrn so in the above string, the python script would find XGTyERQ because the first 3 characters are uppercase and the 4th character is lower, and then the last 3 characters are uppercase. Any ideas??? |
||
|
|||
|
|||
|
Rank: ? (4)
Member #: 27845 |
Hey,
I dont know if am getting your question correclty but to just get a string "XGTyERQ" from runverUNCunruynXGTyERQvbrBNURBNIBuirRGRGRntuvrn is actually pretty straight forward. ================================================================= """Program for playing around with the regular expressions. How it works from command line: >>> import revise_res >>> regex_obj = revise_res.revise_reg_exp() >>> regex_obj.find_different_case("342422ABCaABC23424" ABCaABC >>> regex_obj.find_different_case("runverUNCunruynXGTyERQvbrBNURBNIBuirRGRGRntuvrn" XGTyERQ """ __author__ = "Sesha Srinivas(sesha_srinivas@yahoo.com)" __revision__ = "$Revision:1.2 $" __updates__ = "Added new functionality to run the code from command line" __date__ = "2006/06/21" import re import sys class revise_reg_exp: """Class with regular expressions """ # values to be changed to # Define all your xml elements here def __init__(self): """Compile all regular expressions first, because it is always better to use the compiled object """ self.pattern_string_case = re.compile(r'[A-Z]{1,3}[a-z]{1,1}[A-Z]{1,3}') def find_different_case(self, search_string): """Gets the search string and searches if there is a pattern match Returns the STRING found """ found_string = self.pattern_string_case.search(search_string) print found_string if found_string: print found_string.group() else: print "No match found" =================================================================== If this is not what you want please post again in detail. thanks |
||
|
Please login or register to post a reply.