What does (?i) and ?@ in this regex mean [duplicate]

99封情书 提交于 2020-12-25 00:17:57

问题


In the following regex what does "(?i)" and "?@" mean?

(?i)<.*?@(?P<domain>\w+\.\w+)(?=>)

I know that "?" means zero or one and that i sets case insensitivity.

This regex captures domains from an email address in a mailto field, but does not include the @ sign. It was generated the erex command from within SPLUNK 6.0.2


回答1:


demo here : https://regex101.com/r/hE9gB4/1

(?i)<.*?@(?P<domain>\w+\.\w+)(?=>)

its actually getting your domain name from the email id:

(?i) makes it match case insensitive and

?@ is nothing but @ which matches the character @ literally.

the ? in your ?@ is part of .*? which we call as a lazy operator, It will give you the text between the < and @

if you dont use the ? after the .* it will match everything after < to the end. ( we call this as the greedy operator)




回答2:


? here is the UNGREEDY or LAZYNESS modifier:

.*?

It means: "everything is good until the @ character that follows is detected". Otherwise .* would match everything until the end of the string.

Read about it here: http://www.regular-expressions.info/repeat.html



来源:https://stackoverflow.com/questions/22961535/what-does-i-and-in-this-regex-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!