Remove all characters before a certain character with Python using Field Calculator

11700
4
Jump to solution
11-29-2017 01:13 PM
Brian_McLeer
Occasional Contributor

I have a series of strings that I need to eliminate a series of text. The text can be variable in length, so doing any trim or strip functions will not work. The string is: 

  <img src="X:\UB_Routing\images\ServiceOrders\150 E MAIN ST.png"><br>150 E MAIN ST

or

  <img src="X:\UB_Routing\images\ServiceOrders\3207 SE ROSESPRING DR.png"><br>3207 SE ROSESPRING DR

As a few examples, but they can be any address. 

I am looking for a Python field calculator solution to remove everything before and including the value of <br>

From the examples above, the only values left would be:

150 E MAIN ST

3207 SE ROSESPRING DR

0 Kudos
1 Solution

Accepted Solutions
KevinDunlop
Occasional Contributor III

Try using

!FieldName![!FieldName!.rindex('>')+1:]

View solution in original post

4 Replies
KevinDunlop
Occasional Contributor III

Try using

!FieldName![!FieldName!.rindex('>')+1:]

View solution in original post

Brian_McLeer
Occasional Contributor

Thank worked Kevin, thank you!

0 Kudos
YusefSamari
New Contributor III

Nice solution! I've been trying to repurpose this to remove all characters AFTER a certain character, but I'm stuck. Could you help, please?

0 Kudos
DarrenWiens2
MVP Honored Contributor
my_string = '<img src="X:\UB_Routing\images\ServiceOrders\150 E MAIN ST.png"><br>150 E MAIN ST'
print my_string.split('<br>')[1]

150 E MAIN ST