|
| 1 | +/* |
| 2 | + * CDDL HEADER START |
| 3 | + * |
| 4 | + * The contents of this file are subject to the terms of the |
| 5 | + * Common Development and Distribution License (the "License"). |
| 6 | + * You may not use this file except in compliance with the License. |
| 7 | + * |
| 8 | + * See LICENSE.txt included in this distribution for the specific |
| 9 | + * language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * When distributing Covered Code, include this CDDL HEADER in each |
| 12 | + * file and include the License file at LICENSE.txt. |
| 13 | + * If applicable, add the following below this CDDL HEADER, with the |
| 14 | + * fields enclosed by brackets "[]" replaced with your own identifying |
| 15 | + * information: Portions Copyright [yyyy] [name of copyright owner] |
| 16 | + * |
| 17 | + * CDDL HEADER END |
| 18 | + */ |
| 19 | + |
| 20 | +/* |
| 21 | + * Copyright (c) 2017, Chris Fraire <[email protected]>. |
| 22 | + */ |
| 23 | + |
| 24 | +package org.opensolaris.opengrok.util; |
| 25 | + |
| 26 | +/** |
| 27 | + * Represents a container for regex-related utility methods. |
| 28 | + */ |
| 29 | +public class RegexUtils { |
| 30 | + |
| 31 | + /** Private to enforce singleton. */ |
| 32 | + private RegexUtils() { |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Gets a zero-width expression intended to follow a character match that |
| 37 | + * asserts that the character either does not follow a backslash escape or |
| 38 | + * follows an even number¹ of backslash escapes. |
| 39 | + * <p> |
| 40 | + * ¹"even number" is limited to 2,4,6 because Java look-behind is not |
| 41 | + * variable length but instead must have a definite upper bound in the |
| 42 | + * regex definition. |
| 43 | + * @return a defined expression: |
| 44 | + * <pre> |
| 45 | + * {@code |
| 46 | + * ((?<=^.)|(?<=[^\\].)|(?<=^(\\\\){1,3}.)|(?<=[^\\](\\\\){1,3}.)) |
| 47 | + * } |
| 48 | + * </pre> |
| 49 | + * (Edit above and paste below [in NetBeans] for easy String escaping.) |
| 50 | + */ |
| 51 | + public static String getNotFollowingEscapePattern() { |
| 52 | + return "((?<=^.)|(?<=[^\\\\].)|(?<=^(\\\\\\\\){1,3}.)|(?<=[^\\\\](\\\\\\\\){1,3}.))"; |
| 53 | + } |
| 54 | +} |
0 commit comments