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

16733
5
Jump to solution
11-29-2017 01:13 PM
Brian_McLeer
Occasional Contributor II

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

Brian
0 Kudos
1 Solution

Accepted Solutions
KevinDunlop
Occasional Contributor III

Try using

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

View solution in original post

5 Replies
KevinDunlop
Occasional Contributor III

Try using

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

Brian_McLeer
Occasional Contributor II

Thank worked Kevin, thank you!

Brian
0 Kudos
YusefSamari
Occasional Contributor

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
DianaRathfelder2
New Contributor

I was looking for that too and I found it on another thread (Removing text after comma).  I was trying to remove characters after a &.  I'm not sure the link will link to the thread.

!YourFieldName!.split(",")[0] ‍

 

 

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