title: How to perform regex operations on a string tensor on TensorFlow?
body: <p>How can I perform regex operations on a string tensor? Normally, I would just use a python string but when using Tensorflow Serving, I need my input to be a string tensor. So I created a string placeholder and am just injecting another layer into the graph where I take the placeholder and make it ready for the passing it to the model. </p>
  
  <p>I have looked at using <code>py_func</code>but I still cannot perform pattern operations on a bytes-like object.</p>
  
  <p>Is there any way of performing these operations on a tensor? I cannot do an eval() on the placeholder because the data is only fed in when the savedModel is loaded and run.</p>
  
  <p>Code I have been using for testing:</p>
  
  <pre><code>def remove_urls(vTEXT):
      vTEXT = re.sub(r'(https|http)?:\/\/(\w|\.|\/|\?|\=|\&amp;|\%)*\b', 'url', vTEXT, flags=re.MULTILINE)
      return(vTEXT)
  
  
  input_string_ph = tf.constant("This is string https:www.someurl.com")
  
  input_string_lower = tf.py_func(lambda x: x.lower(), [input_string_ph], tf.string, stateful=False)
  # input_string_no_url = tf.py_func(lambda x: remove_urls(x), [input_string_lower], tf.string, stateful=False)
  sess = tf.InteractiveSession()
  print (input_string_no_url.eval())
  </code></pre>