

Then (?!//) checks that whatever is after the leading whitespace isn't the comment marker, and finally we look for foobar within word breaks anywhere on the line. The user should be able to enter either 'part1' (answer 1), 'part2' (answer 2) or. I have the following situation: The correct solution for the word would be 'part1, part2'. The \s*+ is a "possessive" expression, which matches all leading whitespace, and doesn't let go of them. How is the AND/OR operator represented as in Regular Expressions I'm currently programming a vocabulary algorithm that checks if a user has typed in the word correctly. If, instead, you are restricted to a single Perl regex, then this should work: grep -P '^\s*+(?!//).*\bfoobar\b.*$' file.txt Something like this would match just the uncommented line: $ perl -ne 'print if not m,^\s*//, and /\bfoobar\b/' ' If you're using Perl (the language) and not some tool using Perl-compatible regexes, there's no reason to restrict yourself to just one regex. the reason is because your normal 'foobar' was made up of just word characters and now (\bfoobar\b) will not match it. If you ever replace 'foobar' with some arbitrary string like '$' and you try the above, it will fail. NOTE: you can further finely tune by changing the. This disregards anything having the comment signature '//' anywhere in whitespace, at the beginning, followed by our pattern. We just replace (\s*//\s*) with (?!\s*//\s*) Find Substring within a string that begins and ends with paranthesis. Introduction to regexes in Perl a Just an a character. I hope this Regex Cheat-sheet will provide such aid for you. To negate this we do: "^(?!\s*//\s*).*(\bfoobar\b).*$" Perl 5 Regex Cheat sheet When learning regexes, or when you need to use a feature you have not used yet or dont use often, it can be quite useful to have a place for quick look-up. having the comment signature '//' anywhere in whitespace, at the beginning, followed by anything which includes 'foobar' as a whole word (included brackets for clarity). You can try different expressions by playing around with the Regex by simply running the report DEMOREGEX in. As POSIX is outdated, we will use Perl-style regexes hereinafter.

Both libraries differ significantly in how matches are computed. Since then, Perl library is also supported.

say I am looking to reject these lines: "^(\s*//\s*).*(\bfoobar\b).*$" Up to 7.55 release, ABAP only used POSIX library for RegEx. I think the issue of negation should not be over complicated.Į.g.
