我试图了解正则表达式引擎处理带有后续前瞻语句的表达式的方式。我觉得我可以用两个例子(javascript语法)来最好地说明我的问题。如果我的术语使用不对,请原谅我。
没有前瞻的示例:
/a(.*b)(.*c)/
这将匹配包含a
的表达式,该表达式在某个时刻后跟b
,后面跟c
。(.*c)
。因此第二个原子组(.*b)
“适用于”第一个原子组abc
。 acb
将满足此表达式,但/a(?=.*b)(?=.*c)/
不会。
前瞻示例:
/a(?=.*c)(?=.*b)/
== a
这将与b
匹配,如果某个时间点后跟c
并且,则a
也会跟上a
。因此,无论顺序如何,两个原子组都适用于abc
字符:acb
和a
都会匹配protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_kuliner);
//INITIALIZE VIEWS
nama_kul = (TextView) findViewById(R.id.nameDetail_kul);
lokasi_kul = (TextView) findViewById(R.id.lokasi_kul);
desclong_kul = (TextView) findViewById(R.id.desclong_kul);
image_kul = (ImageView) findViewById(R.id.imageDetail_kul);
//RECEIVE DATA
Intent intent=this.getIntent();
String name_kul=intent.getExtras().getString("NAME_KEY");
String lokas_kul=intent.getExtras().getString("LOKASI_KEY");
final String descshor_kul=intent.getExtras().getString("DESCSHORT_KEY");
String desclon_kul=intent.getExtras().getString("DESCLONG_KEY");
final String images_kul=intent.getExtras().getString("IMAGE_KEY");
//BIND DATA
nama_kul.setText(name_kul);
lokasi_kul.setText(lokas_kul);
desclong_kul.setText(desclon_kul);
Glide.with(this).load(images_kul).into(image_kul);
//Intent to 2nd activity
detail2ButtonStart = (ImageButton) findViewById(R.id.detail2_but);
detail2ButtonStart.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(detail_kuliner.this, detail2_kuliner.class);
intent.putExtra("DESCSHORT2_KEY",descshor_kul);
intent.putExtra("IMAGE2_KEY",images_kul);
//open activity
startActivity(intent);
}
});
。
所以我认为正则表达式引擎对待前瞻(和后瞻?)组的方式不同于他们对待其他组 - 在每次前瞻后,他们是否回到“主”表达式(在这种情况下为public class detail2_kuliner extends AppCompatActivity {
private static final String TAG = detail2_kuliner.class.getSimpleName();
private VrPanoramaView panoWidgetView;
public boolean loadImageSuccessful;
private Uri fileUri;
private Options panoOptions = new Options();
private ImageLoaderTask backgroundImageLoaderTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail2_kuliner);
panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view);
panoWidgetView.setEventListener(new ActivityEventListener());
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
Log.i(TAG, this.hashCode() + ".onNewIntent()");
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Log.i(TAG, "ACTION_VIEW Intent recieved");
fileUri = intent.getData();
if (fileUri == null) {
Log.w(TAG, "No data uri specified. Use \"-d /path/filename\".");
} else {
Log.i(TAG, "Using file " + fileUri.toString());
}
panoOptions.inputType = intent.getIntExtra("inputType", Options.TYPE_MONO);
Log.i(TAG, "Options.inputType = " + panoOptions.inputType);
} else {
Log.i(TAG, "Intent is not ACTION_VIEW. Using default pano image.");
fileUri = null;
panoOptions.inputType = Options.TYPE_MONO;
}
if (backgroundImageLoaderTask != null) {
backgroundImageLoaderTask.cancel(true);
}
backgroundImageLoaderTask = new ImageLoaderTask();
backgroundImageLoaderTask.execute(Pair.create(fileUri, panoOptions));
}
@Override
protected void onPause() {
panoWidgetView.pauseRendering();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
panoWidgetView.resumeRendering();
}
@Override
protected void onDestroy() {
panoWidgetView.shutdown();
if (backgroundImageLoaderTask != null) {
backgroundImageLoaderTask.cancel(true);
}
super.onDestroy();
}
class ImageLoaderTask extends AsyncTask<Pair<Uri, Options>, Void, Boolean> {
@Override
protected Boolean doInBackground(Pair<Uri, Options>... fileInformation) {
Options panoOptions = null;
InputStream istr = null;
if (fileInformation == null || fileInformation.length < 1
|| fileInformation[0] == null || fileInformation[0].first == null) {
AssetManager assetManager = getAssets();
try {
istr = new URL("http://SOME URL IMAGE").openStream(); //How to get SOME URL IMAGE from intent sent at first activity
panoOptions = new Options();
panoOptions.inputType = Options.TYPE_STEREO_OVER_UNDER;
} catch (IOException e) {
Log.e(TAG, "Could not decode default bitmap: " + e);
return false;
}
} else {
try {
istr = new FileInputStream(new File(fileInformation[0].first.getPath()));
panoOptions = fileInformation[0].second;
} catch (IOException e) {
Log.e(TAG, "Could not load file: " + e);
return false;
}
}
panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr), panoOptions);
try {
istr.close();
} catch (IOException e) {
Log.e(TAG, "Could not close input stream: " + e);
}
return true;
}
}
)遇到过吗?
提前感谢您的帮助。