This is a regex specific question..
I need a regex that can find a certain keyword.. Example ABCDE But it should not match if certain characters precede this keyword.. Example ]]
So... In a line like this, it should only match the bold part..
[[TestChannel]] ABCDE: this is a test ABCDE
EDIT: I have been trying things out here.. http://gskinner.com/RegExr/
So far what i have tried..
(!]])(ABCDE)
((!]])ABCDE)
(!]])!(ABCDE)
((!]])|ABCDE)
Solution: With help from the link Pshemo commented -> http://www.regular-expressions.info/lookaround.html#lookbehind
(?<!]])ABCDE
The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a “word boundary”. This match is zero-length. There are three different positions that qualify as word boundaries: Before the first character in the string, if the first character is a word character.
Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself. Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the anchor for the start of the string, or the negation symbol.
String regex = "\\."; Notice that the regular expression String contains two backslashes after each other, and then a . . The reason is, that first the Java compiler interprets the two \\ characters as an escaped Java String character. After the Java compiler is done, only one \ is left, as \\ means the character \ .
\n. Matches a newline character. \r. Matches a carriage return character.
(?<!]])ABCDE
Thanks Pshemo for the links.
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