wildcard

From wildcards to regular expressions

╄→尐↘猪︶ㄣ 提交于 2019-12-06 04:32:27
问题 I want to allow the two main wildcards ? and * to filter my data. Here is how I'm doing now (as I saw on many websites): public boolean contains(String data, String filter) { if(data == null || data.isEmpty()) { return false; } String regex = filter.replace(".", "[.]") .replace("?", ".") .replace("*", ".*"); return Pattern.matches(regex, data); } But shouldn't we escape all the other regex special chars, like | or ( , etc.? And also, maybe we could preserve ? and * if they are preceded by a \

Nested wildcards with lower bounds

心已入冬 提交于 2019-12-06 04:25:57
So I read through the main Java Generic FAQ and the single thing which is holding me up are nested wildcards with lower bounds. I want to give you an example of what I do understand, something specifically which works and how I view it. Maybe you could tell me the way I am thinking about this is wrong even though the compiler isn't complaining in the "good" case. Example 1 (makes sense): static void WildcardsMethod(List<? extends Pair<? extends Number>> list) { System.out.println("It worked"); } static void TestWildcardsMethod() { List<Pair<Integer>> list = null; WildcardsMethod(list); } I

MySQL LIKE operator with wildcard and backslash

霸气de小男生 提交于 2019-12-06 02:54:05
问题 It's frustrated with MySQL's pattern escaping used in LIKE operator. root@dev> create table foo(name varchar(255)); Query OK, 0 rows affected (0.02 sec) root@dev> insert into foo values('with\\slash'); Query OK, 1 row affected (0.00 sec) root@dev> insert into foo values('\\slash'); Query OK, 1 row affected (0.00 sec) root@dev> select * from foo where name like '%\\\\%'; Empty set (0.01 sec) root@dev> select * from foo; +------------+ | name | +------------+ | with\slash | | \slash | +--------

What does an asterisk at the end of a mv command do

末鹿安然 提交于 2019-12-06 02:36:56
问题 So I am going along and moving a bunch of files mv /source /dest & mv /source/* /dest/dest/ & ... ... then I get careless and mv /source/filena* /dest/dest/ * OMG! ^c^c^c^c [No Response from terminal command] What is actually going on here? What happens when I put an * (asterisk) at the end of a command instead of an & (ampersand)? 回答1: The shell expands the wildcard * . The mv command never sees the wildcard, only the result of the expansion. The wildcard * expands to the list of files in

Unbounded wildcard passed to method

巧了我就是萌 提交于 2019-12-05 22:55:50
public class ColTest { static<T> T wildSub(ArrayList<? extends T> holder, T arg){ T t=holder.get(0); return t; } public static void main(String[] args) { ArrayList<?> list=new ArrayList<Long>(Arrays.asList(2L,3L,7L)); Long lng=1L; ColTest.wildSub(list, lng); } } Really interested why this snippet is legal, because the signature of wildSub takes only ArrayList of T or derived from T , and arg of type T . But <?> means - some specific type, not known, and how it can satisfy the compiler? After all type <?> doesn't mean <? extends Long> ... This is due to capture conversion . Internally, compiler

Subdomain wildcard htaccess redirection to new domain

混江龙づ霸主 提交于 2019-12-05 22:37:09
One of my websites I want to redirect o another domain. The situation: [old] *.example.com [new] *.example.net for now I have this in my htaccess #RewriteCond %{HTTP_HOST} ^(.*).allwebsitestats.com [NC] #RewriteRule ^(.*)$ http://$1.allwebsitestats.nl [R=301,L] The result of this; Request [old] *.example.com results in [new] .example.net, the problem is it doesn't get the wildcard subdomain with it. Thanks you! Regards, Nick Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory: Options +FollowSymLinks -MultiViews # Turn mod

SQL Update Replace statement

孤街浪徒 提交于 2019-12-05 21:25:02
I need to write a sql update statement using REPLACE. The string looks like 'SE*88*000000001'. I need to replace the number between the two asterisks '*'. There is no pattern here other then that number to be replaced is always between two asterisks. Is it possible to use wild cards in this situation? Appreciate your help. Thanks! ; WITH RowSetToUpdate AS ( SELECT acolumn, Asterisk1Pos = CHARINDEX('*', acolumn), Asterisk2Pos = CHARINDEX('*', acolumn, CHARINDEX('*', acolumn) + 1) FROM atable WHERE acolumn LIKE '%*%*%' ) UPDATE RowSetToUpdate SET acolumn = STUFF( acolumn, Asterisk1Pos + 1,

Java HashMap with ArrayList wildcards

人盡茶涼 提交于 2019-12-05 18:16:47
I have a HashMap where the values are ArrayLists, and I'm trying to write a function to accept generic instances of these HashMaps HashMap<String, ArrayList<Integer>> myMap = new HashMap<String, ArrayList<Integer>>(); public static void foo(HashMap<?, ArrayList<?>> a) {} public static void bar(HashMap<?, ? extends ArrayList<?>> a) {} // Compilation Failure! foo(myMap); // This works, but why do I need ? extends ArrayList bar(myMap) The error message is The method foo(HashMap<?,ArrayList<?>>) in the type Example is not applicable for the arguments ( HashMap<String,ArrayList<Integer>> ). Why do

Demystify Wildcard for me

孤街醉人 提交于 2019-12-05 16:56:21
Why do I get a compile time error on this piece of code? public Interface Location { ....... } Class code... Map<Type, List<? extends Location>> locationsTypeMap = new HashMap<Type, List<? extends Location>>(); /** Code to add elements to the hashMap. */ newLocation = getNewLocation() while(mapHasElements){ Location.Type key = location.getType(); List<? extends Location> valueList = (List<? extends Location>)locationsTypeMap.get(key); //1 valueList.add(newLocation);/*Compile error*/ } On the other hand, if I replace step 1 with line below it works List<Location> valueList = (List<Location>

How to search for files with a wildcard in Common Lisp?

余生颓废 提交于 2019-12-05 16:55:33
I am not satisfied to find files matching a string like this: (remove-if-not (lambda (it) (search "wildcard" (namestring it))) (uiop:directory-files "./")) ;; I'll ignore case with str:contains? ;; https://github.com/vindarel/cl-str How would one search for files with unix-style wildcards ? If it is not built-in, I'd enjoy a solution with uiop . Maybe there is with Osicat or cl-fad (with which it doesn't seem so, the documentation oftentimes says "non-wild pathname"). Bonus if it is possible to use the double wildcard to traverse directories recursively ( ./**/*.jpg ). edit : I have tried