I'm doing some testing with MonetDB.
The gist of the query I'm trying perform (using borrowed syntax) goes like this:
SELECT mystring FROM mytable WHERE mystring REGEXP 'myxpression';
MonetDB does not support this syntax, but the docs claim that it supports PCRE, so this may be possible, still the syntax eludes me.
Check the Does MonetDB support regular expression predicates?
The implementation is there in the MonetDB backend, the module that
implements it is pcre (to be found in MonetDB5 source tree).
I'm not sure whether it is available by default from MonetDB/SQL.
If not, with these two function definition, you link SQL functions to the
respective implementations in MonetDB5:
-- case sensitive
create function pcre_match(s string, pattern string)
returns BOOLEAN
external name pcre.match;
-- case insensitive
create function pcre_imatch(s string, pattern string)
returns BOOLEAN
external name pcre.imatch;
If you need more, I'd suggest to have a look at MonetDB5/src/modules/mal/
pcre.mx in the source code.
Use select name from sys.functions; to check if the function exists, otherwise you will need to create it.
As an example, you may use pcre_imatch() like this:
SELECT mystring FROM mytable WHERE pcre_imatch(mystring, 'myexpression');
Related
I am trying to avoid using a regexp function when I need to match strings regardless to their accent or case. For instance, when I search for "VOILA", I want to match "voilà".
I noted that it is possible to create a custom collation to achieve that but I don't know where to start and what to expect in terms of performance:
I assume it will be faster than my REGEXP function defined in my VB.net code (see code below). Is that correct? EDIT: this approach doesn't work. I guess the regex is false. Since I am looking for another solution, I'll wait for answers instead of fixing it.
_
Class MyRegEx
Inherits SQLiteFunction
Public Overrides Function Invoke(args As Object()) As Object
Return System.Text.RegularExpressions.Regex.IsMatch(Convert.ToString(args(1)), Convert.ToString(args(0)))
End Function
End Class
The regex build:
Dim testString As String = word.Replace("A", "[=a=]")
testString = testString.Replace("E", "[=e=]")
testString = testString.Replace("I", "[=i=]")
testString = testString.Replace("O", "[=o=]")
testString = testString.Replace("U", "[=u=]")
testString = testString.Replace("Œ", "œ")
testString = "(?i)(\W|^)" & testString & "(\W|$)"
I have read the SQLite documentation on the creation of a custom collation but I don't really get it. Should I define this in my .net application? Can I embed my custom collation in the database to avoid to create it each time?
I guess that it's a common issue considering the number of related questions. However, I haven't seen a single written example achieving this kind of accent/case insensitive search. Can someone share this?
The best lead I have so far would be to create a custom column without accents as described here. This approach seems to be satisfying, but I wanted to get the elegant solution (i.e. custom collate) instead, if it is possible in my case.
Thanks!
I can't get case insensitive searches to work for REGEX in SQLITE. Is the syntax supported?
SELECT * FROM table WHERE name REGEXP 'smith[s]*\i'
I would expect the following answers (assuming the database has these entries):
Smith
Smiths
smith
smitH <--- Not a typo but in database
Note - This is a small part of a larger REGEX, so I won't be using LIKE
As described by CL, this feature is not supported in SQLite. A simple solution to this problem is to "lowercase" the left-hand side of the REGEXP expression using lower:
SELECT * FROM table WHERE lower(name) REGEXP 'smith[s]*';
it is not ideal, but it works. But pay attention to diacritics. I would read the documentation for lower if your text uses them.
The REGEXP function shipped with SQLite Manager is implented in JavaScript as follows:
var regExp = new RegExp(aValues.getString(0));
var strVal = new String(aValues.getString(1));
if (strVal.match(regExp)) return 1;
else return 0;
To get case-insensitive searches with the JavaScript RegExp object, you would not add a flag to the pattern string itself, but pass the i flag in the second parameter to the RegExp constructor. However, the binary REGEXP operator does not have a third flags parameter, and the code does not try to extract flags from the pattern, so these flags are not supported in this implementation.
From https://www.sqlite.org/lang_expr.html
If an application-defined SQL function named "regexp" is added at run-time, then the "X REGEXP Y" operator will be implemented as a call to "regexp(Y,X)".
I'm trying to search the documentation for a data element whose description contains the string '*hh:mm' but not 'mm:ss' (where '' is a wildcard for any number of characters).
I don't know how to do it, so I was wondering if any of you know the regex system SAP GUI uses, so I can have a look at what I can do with it.
Thx, you guys rule!
The GUI does not give you the opportunity to use regular expressions. You're limited to a simple pattern matching using * and ?. Furthermore, it's a bad idea to search using the description text because the text and the search is case sensitive - you'd find "hh:mm", but not "HH:MM". In the special case you mention, you could use the repository infosystem to search for domains based on the data type TIMS but with an output length of 5 and then use the where-used index to find out a corresponding data element. (It might even be possible to search for a data element based on a certain data type, I'm not entirely sure.)
As of release 7.0, ABAP supports extended regular expressions in accordance with POSIX standard 1003.2.
The classes CL_ABAP_REGEX and CL_ABAP_MATCHER permit object-oriented use of regular expressions.
More detail here
I have classes with many, many empty methods called getFieldNameX or getFieldNameY (implementing a big interface for many columned linq to sql tables). I want to insert return values using find and replace.
This is that have
Function GetInsertedDate() as Date implements myInterface.getInsertedDate
End Function
This is what I want:
Function GetInsertedDate() as Date implements myInterface.getInsertedDate
return me.insertedDate //"return me." + method signature minus get
End Function
Is there any way to do this with find and replace?
Find: myInterface\.get{.+}\n\n
Replace: myInterface.get\1\n\treturn me.\1\n
Use: Regular expressions
search for getInsertedDate
and replace with getInsertedDate\n\treturn me.insertedDate with Use: Regular expressions enabled
I write a mysql query
select * from table where name like '%salil%'
which works fine but it will no return records with name 'sal-il', 'sa#lil'.
So i want a query something like below
select * from table whereremove_special_character_from(name)like '%salil%'
remove_special_character_from(name) is a mysql method or a regular expression which remove all the special characters from name before like executed.
No, mysql doesn't support regexp based replace.
I'd suggest to use normalized versions of the search terms, stored in the separate fields.
So, at insert time you strip all non-alpha characters from the data and store it in the data_norm field for the future searches.
Since I know no way to do this, I'd use a "calculated column" for this, i.e. a column which depends on the value of name but without the special characters. This way, the cost for the transformation is paid only once and you can even create an index on the new column.
See this answer how to do this.
I agree with Aaron and Col. Shrapnel that you should use an extra column on the table e.g. search_name to store a normalised version of the name.
I noticed that this question was originally tagged ruby-on-rails. If this is part of a Rails application then you can use a before_save callback to set the value of this field.
In MYSQL 5.1 you can use REGEXP to do regular expression matching like this
SELECT * FROM foo WHERE bar REGEXP "baz"
see http://dev.mysql.com/doc/refman/5.1/en/regexp.html
However, take note that it will be slow and you should do what others posters suggested and store the clean value in a separate field.