lookahead

How does the regular expression ‘(?<=#)[^#]+(?=#)’ work?

爱⌒轻易说出口 提交于 2019-11-26 03:40:23
问题 I have the following regex in a C# program, and have difficulties understanding it: (?<=#)[^#]+(?=#) I\'ll break it down to what I think I understood: (?<=#) a group, matching a hash. what\'s `?<=`? [^#]+ one or more non-hashes (used to achieve non-greediness) (?=#) another group, matching a hash. what\'s the `?=`? So the problem I have is the ?<= and ?< part. From reading MSDN, ?<name> is used for naming groups, but in this case the angle bracket is never closed. I couldn\'t find ?= in the

Regular Expressions: Is there an AND operator?

馋奶兔 提交于 2019-11-25 21:44:52
问题 Obviously, you can use the | (pipe?) to represent OR , but is there a way to represent AND as well? Specifically, I\'d like to match paragraphs of text that contain ALL of a certain phrase, but in no particular order. 回答1: Use a non-consuming regular expression. The typical (i.e. Perl/Java) notation is: (?= expr ) This means "match expr but after that continue matching at the original match-point." You can do as many of these as you want, and this will be an "and." Example: (?=match this