Reputation: 11
Here is on sample string:
NOMIGO* TATRA RR ER RR RR RA EEE E RR KH Dollars (U.S. $547,560.00
I am trying to remove "any" or random characters to the left of (U.S. (in Python) note the characters in this example are random and they will change. It needs to work with any characters present to the left of (U.S The number of characters could also change.
Upvotes: 0
Views: 582
Reputation: 584
value = "NOMIGO* TATRA RR ER RR RR RA EEE E RR KH Dollars (U.S. $547,560.00"
split the value at "U.S."
with split_value = value.split("U.S.")
This will split the string value
into two sub-strings :
"NOMIGO* TATRA RR ER RR RR RA EEE E RR KH Dollars ("
and
" $547,560.00"
You want the second substring which is stored at index 1
result = "U.S." + split_value[1] # you probably also want the `"U.S."`, so we add it back
Upvotes: 0
Reputation: 103
You can use slicing
s = "NOMIGO* TATRA RR ER RR RR RA EEE E RR KH Dollars (U.S. $547,560.00"
s = s[s.find("(U.S."):]
print(s)
Output: (U.S. $547,560.00
Upvotes: 1