首页 \ 问答 \ PHP PCRE - 匹配“没什么”(PHP PCRE - match “nothing”)

PHP PCRE - 匹配“没什么”(PHP PCRE - match “nothing”)

我正在尝试将我的应用程序uri与一组路由匹配,对于默认路由,我考虑允许bb.com/homebb.com/ (空)成为第一个uri段上允许的选项,并且同样的第二个。 我不确定我检查空值的方式是最好的:

#^/?(?P<controller>([.*]{0}|home))(?:/(?P<action>([.*]{0}|test)))?/?$#uD

注意 [.*]{0}

有没有更好的方法呢?


I'm trying to match my application uri to a set of routes, and for the default route I thought about allowing bb.com/home or bb.com/ (empty) to be the allowed options on the first uri segment, and the same for the second. I'm not sure the way I am checking for empty values is the best :

#^/?(?P<controller>([.*]{0}|home))(?:/(?P<action>([.*]{0}|test)))?/?$#uD

Notice the [.*]{0}

Is there a better way to do it?


原文:https://stackoverflow.com/questions/20626409
更新时间:2023-03-02 10:03

最满意答案

                   <LinearLayout
                    style="@style/Widget.CardContent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


    <!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
                          <LinearLayout
                          android:focusable="true" 
                          android:focusableInTouchMode="true"
                          android:layout_width="0px" 
                          android:layout_height="0px"/>

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/event_title"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textPersonName"
                            android:hint="@string/edit_text_title" />
                    </android.support.design.widget.TextInputLayout>
                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/txtInputLayoutPassword"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/event_description"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textMultiLine"
                            android:hint="@string/edit_text_description" />
                    </android.support.design.widget.TextInputLayout>
                </LinearLayout>

                   <LinearLayout
                    style="@style/Widget.CardContent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


    <!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
                          <LinearLayout
                          android:focusable="true" 
                          android:focusableInTouchMode="true"
                          android:layout_width="0px" 
                          android:layout_height="0px"/>

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/event_title"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textPersonName"
                            android:hint="@string/edit_text_title" />
                    </android.support.design.widget.TextInputLayout>
                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/txtInputLayoutPassword"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/event_description"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textMultiLine"
                            android:hint="@string/edit_text_description" />
                    </android.support.design.widget.TextInputLayout>
                </LinearLayout>

相关问答

更多
  • 默认情况下,创建微调器时,将选择索引0处的项目。 因此,即使用户实际上没有做任何事情,也会选择第一个项目。 您可以通过在onItemSelected()中设置断点(或其他一些通知)并看到它在启动时触发而无需用户执行任何操作来实现。 要使onNothingSelected()回调被触发,所选的任何项都必须消失。 By default, the item at index 0 is selected when you spinner is created. So, even though the user do ...
  • 我不知道这样做的直接方法是否可用,但是你确实有一个解决方法通过代码:listen onFocus事件的EditText ,并且一旦获得焦点,设置提示是没有什么像editText.setHint("") : 这可能不是你必须做的,但它可能是这样的东西 - myEditText.setOnFocusListener(new OnFocusListener(){ public void onFocus(){ myEditText.setHint(""); } }); I don't know w ...
  • 您可以使用setHighlightColor方法。 editText.setHighlightColor(ContextCompat.getColor(this, R.color.someColor)); 如果在Fragment中使用比使用此: editText.setHighlightColor(ContextCompat.getColor(getContext(), R.color.someColor)); 您可以将颜色设置为值 - > colors.xml
    你知道SubString吗? String contents = et1.getText().toString(); et1.setText(contents.substring(0, contents.length()-2)); Do you know about SubString? String contents = et1.getText().toString(); et1.setText(contents.substring(0, contents.length()-2));
  • 如果我理解正确,你想要做到以下几点: 在聚焦firstEText ,选择firstEText所有文本firstEText设置为“00” 。 我不明白的是为什么你说你不能使用setOnFocusChangeListener ,因为它可用于API 1之后 。 一个方便的属性来选择一个EditText的所有文本,当获得一个元素的焦点时,是android:selectAllOnFocus ,它正是你想要的。 然后,您只需要将secondEText设置为“00” 。 UI
  • 拿出android:textIsSelectable="true" 。 要么 编辑: 如果您需要能够将文本保留为新的编辑文本的一部分: 将android:提示更改为andoid:text可以使用键盘使用文本。 但是,如果键盘关闭,它仍然需要返回到第一个编辑文本,它将保持打开第二个edtitext。 对于两个edittext框,我将使用height作为“wrap_content”。
  • Heyy Vu Duong,我尝试过这样的事情。 希望这可以帮助你 @Override public void afterTextChanged(Editable s) { if (!s.toString().equals(current)) { inputValue.removeTextChangedListener(this); String cleanString = s.toString().replaceAll("\\ ...