用于匹配双引号但不是反斜杠的正则表达式 - 双引号

时间:2016-08-06 22:21:33

标签: java regex string

我需要正则表达式来匹配双引号字符" ,但如果它前面有反斜杠\"则不需要。

我到了[^\\]",但是它选择了两个字符:"和前面的任何(除了\),我只需要选择"个字符。

我需要解析流中的行,如下所示: command "string1" "string2"字符串可以包含空格和转义双引号。我需要拆分它以便我得到命令,string1和string2作为数组。

提前致谢

2 个答案:

答案 0 :(得分:3)

你可以使用负面的后卫: 08-06 21:47:24.894 26334-26334/com.example.xxxxx E/ACRA: ACRA caught a InflateException for com.example.xxxxx android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.example.gu.NeckCanvasOverlay at android.view.LayoutInflater.inflate(LayoutInflater.java:551) at android.view.LayoutInflater.inflate(LayoutInflater.java:429) at com.example.xxxxx.FragmentNeckDisplayMenu.onCreateView(FragmentNeckDisplayMenu.java:32) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) at android.support.v4.view.ViewPager.populate(ViewPager.java:1106) at android.support.v4.view.ViewPager.populate(ViewPager.java:952) at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:733) at com.example.xxxxx.PlayFrets.configMenu(PlayFrets.java:150) at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:125) at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:9) at android.os.AsyncTask.finish(AsyncTask.java:651) at android.os.AsyncTask.access$500(AsyncTask.java:180) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.example.gu.NeckCanvasOverlay at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) at android.view.LayoutInflater.rInflate(LayoutInflater.java:855) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) at android.view.LayoutInflater.inflate(LayoutInflater.java:527) at android.view.LayoutInflater.inflate(LayoutInflater.java:429)  at com.example.xxxxx.FragmentNeckDisplayMenu.onCreateView(FragmentNeckDisplayMenu.java:32)  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)  at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)  at android.support.v4.view.ViewPager.populate(ViewPager.java:952)  at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:733)  at com.example.xxxxx.PlayFrets.configMenu(PlayFrets.java:150)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:125)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:9)  at android.os.AsyncTask.finish(AsyncTask.java:651)  at android.os.AsyncTask.access$500(AsyncTask.java:180)  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:158)  at android.app.ActivityThread.main(ActivityThread.java:7229)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.gu.NeckCanvasOverlay" on path: DexPathList[[zip file "/data/app/com.example.xxxxx-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.xxxxx-2/lib/arm64, /vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at android.view.LayoutInflater.createView(LayoutInflater.java:595) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)  at android.view.LayoutInflater.inflate(LayoutInflater.java:527)  at android.view.LayoutInflater.inflate(LayoutInflater.java:429)  at com.example.xxxxx.FragmentNeckDisplayMenu.onCreateView(FragmentNeckDisplayMenu.java:32)  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)  at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)  at android.support.v4.view.ViewPager.populate(ViewPager.java:952)  at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:733)  at com.example.xxxxx.PlayFrets.configMenu(PlayFrets.java:150)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:125)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:9)  at android.os.AsyncTask.finish(AsyncTask.java:651)  at android.os.AsyncTask.access$500(AsyncTask.java:180)  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:158)  at android.app.ActivityThread.main(ActivityThread.java:7229)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  Suppressed: java.lang.ClassNotFoundException: com.example.gu.NeckCanvasOverlay at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 33 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available 08-06 21:47:24.954 26334-27123/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.xxxxx, PID: 26334 android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.example.gu.NeckCanvasOverlay at android.view.LayoutInflater.inflate(LayoutInflater.java:551) at android.view.LayoutInflater.inflate(LayoutInflater.java:429) at com.example.xxxxx.FragmentNeckDisplayMenu.onCreateView(FragmentNeckDisplayMenu.java:32) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613) at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) at android.support.v4.view.ViewPager.populate(ViewPager.java:1106) at android.support.v4.view.ViewPager.populate(ViewPager.java:952) at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:733) at com.example.xxxxx.PlayFrets.configMenu(PlayFrets.java:150) at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:125) at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:9) at android.os.AsyncTask.finish(AsyncTask.java:651) at android.os.AsyncTask.access$500(AsyncTask.java:180) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.example.gu.NeckCanvasOverlay at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) at android.view.LayoutInflater.rInflate(LayoutInflater.java:855) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) at android.view.LayoutInflater.inflate(LayoutInflater.java:527) at android.view.LayoutInflater.inflate(LayoutInflater.java:429)  at com.example.xxxxx.FragmentNeckDisplayMenu.onCreateView(FragmentNeckDisplayMenu.java:32)  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)  at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)  at android.support.v4.view.ViewPager.populate(ViewPager.java:952)  at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:733)  at com.example.xxxxx.PlayFrets.configMenu(PlayFrets.java:150)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:125)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:9)  at android.os.AsyncTask.finish(AsyncTask.java:651)  at android.os.AsyncTask.access$500(AsyncTask.java:180)  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:158)  at android.app.ActivityThread.main(ActivityThread.java:7229)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.gu.NeckCanvasOverlay" on path: DexPathList[[zip file "/data/app/com.example.xxxxx-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.xxxxx-2/lib/arm64, /vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at android.view.LayoutInflater.createView(LayoutInflater.java:595) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)  at android.view.LayoutInflater.inflate(LayoutInflater.java:527)  at android.view.LayoutInflater.inflate(LayoutInflater.java:429)  at com.example.xxxxx.FragmentNeckDisplayMenu.onCreateView(FragmentNeckDisplayMenu.java:32)  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)  at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)  at android.support.v4.view.ViewPager.populate(ViewPager.java:952)  at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:733)  at com.example.xxxxx.PlayFrets.configMenu(PlayFrets.java:150)  at com.example.xxxxx.AsyncTask_NoteFileLoader.onPostExecute(AsyncTask_NoteFileLoader.java:125) 

(?<!\\)"表示(?<!reg1)reg2必须在reg2之前。请注意,不会捕获reg1

现在在Java代码中,你的正则表达式看起来会略有不同,因为你需要转义双引号和两个反斜杠:

reg1

答案 1 :(得分:1)

您可以使用negative lookbehind:匹配LANG=en_US.UTF-8 前面没有",例如:

\\