Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

regex

splunk

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

like image 741
Deesbek Avatar asked Apr 09 '14 11:04

Deesbek


People also ask

How do you match duplicate words in regex?

Following example shows how to search duplicate words in a regular expression by using p. matcher() method and m. group() method of regex. Matcher class.

What is the significance of (? I used in regular expression in Unix?

2. What is the significance of $ used in regular expression in UNIX? Explanation: Regular expression provides more flexibility while matching string patterns.

What does regex (? S match?

3.6. (? i) makes the regex case insensitive. (? s) for "single line mode" makes the dot match all characters, including line breaks.

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.


2 Answers

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)

like image 57
aelor Avatar answered Sep 28 '22 04:09

aelor


? 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

like image 38
Cagy79 Avatar answered Sep 28 '22 03:09

Cagy79