我正在尝试使用正则表达式在Drupal 8视图[Exposed Filter]中过滤出结果。我需要在特定字段的后4或5位数字/字母中搜索关键字。
例如:
- 2006ABC00022
- 2014DEF03120
- 2019年
- 2019年
These are the data I need to filter. If someone tried to search "0022"
I want to show the result as 2006ABC00022
. Because the last 4 digit is 0022. We can use Ends with
operator to do this. But I want something different because If someone tried to filter the result with "312"
I want to show the results as 2014DEF03120
and 2019GHI03128
. Because these 2 strings have 312
as starting of the last 4 digits. This scenario will not work if I use 'Ends with' operator. So I go for a regular expression.
"[0- 9]{4}$"
I tried to use the regex with the above one. And I realize that this is not working as I expected. This one is searching all over the string.
If I search for 2019
it shows the last 2 results. But it should be empty.
我只想搜索最后4位数字上的关键字。如果关键字是5位数字,则搜索最后5位数字。
似乎有效的匹配是一个以四位数年份开始的关键字,然后是三个字母,然后是5位数字。这意味着以下模式:
Specifically, if you wanted to find matches ending in
0022
then modify the above pattern and use: