逃脱蜂巢中的正则报价
自昨天以来,我尝试在Hive上写下正则表达式
Select regexp_extract(MyColumn,'Clôture de l''intervention(.*)"typeid"',0) as MyColumn
from MyTable
这个正则返回一个空的结果,但应该返回一些东西。
如果我以这种方式尝试,那么较短的方式:
Select regexp_extract(MyColumn,'Clôture de l(.*)"typeid"',0) as MyColumn
from MyTable
它返回某些东西,所以我想问题是单个报价。
如何将其逃脱以将其包含在我的正则表达式中?
感谢您的帮助
I'm trying since yesterday to write a regex in hive
Select regexp_extract(MyColumn,'Clôture de l''intervention(.*)"typeid"',0) as MyColumn
from MyTable
This regex return an empty result but it should return something.
if i try it this way, shorter way :
Select regexp_extract(MyColumn,'Clôture de l(.*)"typeid"',0) as MyColumn
from MyTable
It returns something so i guess the problem is the single quote.
How can i escape it to include it in my regex ?
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想使用“ \'”。那是[backslash] [QUOTE]。但还请记住,您也可以懒惰,然后使用“”。这将与任何单个角色匹配,但通常可以作为这种情况的很好的作弊。
您应该使用:
或
使用SPARK的示例,但仅仅是它起作用的示例。 (并且被逃脱为字符串,因此工作有些不同。)
但是,这确实向您展示了如何在正则言论中工作以使其正常工作。简单开始:
这应该可以解决,很容易。然后播放它,直到添加一个字符,直到将语法正确
作为字符串正确,然后将其移动到Regexp中,然后一次添加一个字符以使其正常工作。
您无需在表上运行,只需使用字符串并慢慢地将字符添加到一个字符中即可使其正常工作。
You want to use a "\'". That is a [backslash][quote]. But also remember you can also be lazy and just use "." which will match any single character, but often works as a good cheat for situations like this.
You should use:
or
Example using spark but just an example of it working. (And is escaped as a string so works a little different.)
But this does show you how to work on your regexp to make it work. Start simple:
This should work out of the box and is easy. Then play with it until adding a character at time until you get the syntax correct
Once you have it correct as a string then move it into regexp and again add a character at a time making it work.
You don't need to run on a table, just use a string and slowly add characters to one by one to make it work.