【发布时间】:2019-07-08 21:13:46
【问题描述】:
我正在尝试使用反向引用来匹配所有使用 ripgrep 实例化的导入类,并启用 --pcre2 选项。
首先,我希望查看是否正在导入一个类,然后返回引用该类以查找它的实例化位置。
第一次尝试:匹配第一次出现的
new ExifInterface(str)我的正则表达式是:(import.+(ExifInterface)).+(new\s\2\(.+\))第二次尝试:匹配最后一次出现的
new ExifInterface(str)。我的正则表达式是(import.+(ExifInterface)).+(?:.+?(new\s\2\(.+\)))
我的ripgrep 命令是rg --pcre2 --multiline-dotall -U "(import.+(ExifInterface)).+(new\s\2\(.+?\))" -r '$3' -o
问题。我怎样才能匹配new ExifInterface(str)的所有出现次数
额外问题:在某些情况下,我从rg 得到了一个PCRE2: error matching: match limit exceeded stderr,但不知道为什么。文档长度只有 161 行。
考虑以下数据样本:
import android.graphics.Point;
import android.media.ExifInterface;
import android.view.WindowManager;
import java.io.IOException;
public class MediaUtils {
/* renamed from: a */
public static float m13571a(String str) {
if (str == null || str.isEmpty()) {
throw new IllegalArgumentException("getRotationDegreeForImage requires a valid source uri!");
}
try {
int attributeInt = new ExifInterface(str).getAttributeInt("Orientation", 1);
if (attributeInt == 3) {
return 180.0f;
new ExifInterface(str).getAttributeInt("Orientation", 1);
}
if (attributeInt == 6) {
return 90.0f;
}
【问题讨论】:
-
您使用什么语言?您使用的是 grep 之类的实用程序吗?
-
OP 在第一段中特别提到了
ripgrep。 -
哦,我以为他在使用一种语言。本来打算告诉你如何使用
\G构造来做到这一点,但现在猜不到。 -
如果 PCRE 支持,那么这里也适用。
-
支持,但用法是重复匹配,不是grep。 Grep 每次都重新开始。