【问题标题】:Backreference in tf.strings.regex_replacetf.strings.regex_replace 中的反向引用
【发布时间】:2022-06-15 22:21:57
【问题描述】:

我想删除重复的字符,例如hhhh,verrrry 使用 tf.strings.regex_replace 从给定的字符串中提取。我使用了以下表达式

lcased = tf.strings.regex_replace(lcased, r'(.)\1{2,}', r'\1')  # repeated chars

但它通过一个错误

"tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid pattern: (.)\1{2,}, error: invalid escape sequence: \1 [Op:StaticRegexReplace]"

【问题讨论】:

  • 这个tf.strings.regex_replace函数使用的正则库是RE2,不支持反向引用。
  • 是否有变通方法来达到相同的结果?
  • 是的,请说明所有可能性...但这对于所有 Unicode 字母来说并不是一个合理的解决方法。

标签: python regex string tensorflow


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-12
  • 2021-04-18
  • 2011-02-13
  • 2013-04-04
  • 2012-10-30
  • 1970-01-01
相关资源
最近更新 更多