What I really need to know is :
(?(
mean ??:
mean ?The regex I am trying to figure out is :
(notice the above mentioned symbols in the following regex)
(?(?=and )(and )|(blah))(?:[1][9]|[2][0])[0-9][0-9]
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
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. 1* means any number of ones.
Short for regular expression, a regex is a string of text that lets you create patterns that help match, locate, and manage text. Perl is a great example of a programming language that utilizes regular expressions. However, its only one of the many places you can find regular expressions.
(?(?=and )(and )|(blah))
pattern is used like if-then-else like (?(expression)yes|no)
i.e and
would be matched if and
is there else blah
would be matched
(?:)
is a non capturing group.So it would not be included in the group or be used as back-reference \1
So,
(?(?=and )(and )|(blah))(?:[1][9]|[2][0])[0-9][0-9]
would match
and 1900
blah2000
and 2012
blah2013
NOTE(it's all about the groups)
The samething can be achievend with this regex
(and |blah)(?:[1][9]|[2][0])[0-9][0-9]
.
The only thing in which these regex differ is the number of groups formed.
So my regex would form 1 group which would contain either and
or blah
Your regex would form no groups.It will form a group only if it matches blah
..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With