MariaDB search using REGEXP - mysql

I am having trouble formulating a valid regular expression for searching in mysql, on a MariaDB database.
I am doing these searches in phpMyAdmin, but will eventually also being doing them in the Search-Replace-DB tool (which is also MySQL based).
Let's say the table I am searching is table-x, and the field is field-y. I need to find the string \root\localhost/cf/.
Here's an example of the data that contains this string:
O:8:"stdClass":2:{s:4:"file";s:58:"\root\localhost/cf//wp-content/wflogs/config-transient.php";s:4:"hash";s:64:"96e5846450f943eeb94993173c13f1dc28a824eff513d1d8019011515b8729f9";}
I tried this regular expression, which works in my expression tester, but doesn't work in MySQL:
\\root\\localhost/cf/. The entire query being,
SELECT * FROM table-x WHERE field-y REGEXP '\\root\\localhost/cf/'.
This gave me the error, #1139 - Got error 'PCRE does not support \L, \l, \N{name}, \U, or \u at offset 6' from regexp.
To get around the \l in my expression, I tried the following:
SELECT * FROM table-x WHERE field-y REGEXP '\\root\\.ocalhost\/cf\/'
This works in my reg exp tester. But it gives no results in phpmyadmin. It did get rid of the PCRE error message though.
What's the correct way to go about this?

Related

MySQL Workbench "->" Support

It looks like MySQL Workbench is now supporting JSON functionality, however I'm still seeing parser errors on MySQL 5.7.9 functionality, such as the "->" operator.
When I use the following query, I'm getting a syntax error over the "$.test" portion:
Record
record: {"test": 123}
Query
SELECT test->"$.test" FROM table
The query still executes successfully, however I'm curious as to why the syntax parser is incorrectly showing an error.
OK, the problem is probably something else than what I posted in my comments. You are using double quotes, which represent strings only if the ANSI quotes are not enabled (then they wrap identifiers). Use single quotes instead.

Regex not supported in sql command with "contains" clause

I am not a seasonal Windows user, I got a task wherein I had to query the Window Index search table i.e "Systemindex" for fetching some user specific data from the db.
And for this I have to match a pattern basically a regular expression while fetching the data.
SELECT System.FileName, System.ItemPathDisplay, System.DateCreated, System.DateModified, System.ItemName, System.KindText FROM Systemindex WHERE Contains('“(?=^[A-Za-z\d!##\$%\^&\*\(\)_\+=]{9,32}$)”');
The above would allow us to search for say stored passwords.
But when I query the db using the below command I was getting an error. And later I came to know that the "contains" clause
does not support regular expression. Is there an alternative to achieve this?
there is REGEXP operator http://dev.mysql.com/doc/refman/5.7/en/regexp.html,
use smth like this
SELECT * FROM Systemindex WHERE some_column REGEXP 'your_regex'

Got error 'repetition-operator operand invalid' from regexp in Mysql

I'm having trouble using a regular expression to select some results from my MySQL table.
I'm using this query
select id, orderid, `desc`
from paymentlog
where `desc` REGEXP '[^.]*(?:_SVD(\d*))[[:>:]]'
And it says
#1139 - Got error 'repetition-operator operand invalid' from regexp
This regex works well with my other editors/validators.
Any advice much appreciated.
MySQL regular expressions don't support the full syntax of Perl-Compatible Regular Expressions.
The (?:) grouping syntax is not supported in MySQL. That syntax is for grouping without backreferences. But it doesn't matter in MySQL, since MySQL doesn't support backreferences anyway (related to this, MySQL has no regular expression substitution function).
In fact, you don't need any parens in your example.
As #ruakh says, \d isn't a code to match digits. You need to use POSIX character classes in MySQL.
So your expression should look like this:
where `desc` REGEXP '_SVD[:digit:]*[[:>:]]'
I also left out your [^.]* since it doesn't matter in this expression. You aren't matching the beginning of the string, so zero characters of that class would succeed the match even if you did have a . before the rest of the pattern. You might mean to match only if you have non-dot characters from the start of the string, like this:
where `desc` REGEXP '^[^.]*_SVD[:digit:]*[[:>:]]'

Select value with odd chars from mysql

I have a field in a mysql database with a strange value:
????!"?;%:?*()_+,??????/????\/
The problem is I cannot select it - the following statement returns no rows
SELECT *
FROM `pool_tag` AS `Extent1`
where `Extent1`.`PoolTag`='????!"?;%:?*()_+,??????/????\/'
The value contains "
I was trying also to use rule to duplicate cotation sign, so used this sql
SELECT *
FROM `pool_tag` AS `Extent1`
where `Extent1`.`PoolTag`="????!**""**?;%:?*()_+,??????/????\/"
(note double cotation marks on position 6)
But still no result
The other problem might be, even if I find a specific syntax to handle in sql query directly, I need to select this from Entity Framework (actually the query you saw wa generated by EF)
Any idea how to handle this?
EDIT
I found about mysql escape chars, I checked all one by one (", ', \, %) and I dicovered that % cause the problems.
If I remove it from both field and search value, sql works
If I leave it in field, and try to escape it in sql select, code still don't work
e.g.
SELECT *
FROM `pool_tag` AS `Extent1`
where `Extent1`.`PoolTag`="????!?;\%:?"
does not find the value
????!?;%:?
Any idea why?

How do I search and replace using regex in MySQL?

I'm trying to update a field which contains HTML and I want to find all the rows that have forms in them and remove the form tags and anything in between them, however I'm running into problems with my select and the regex.
SELECT * FROM db.table WHERE body REGEXP "<form[^>].+?>.+?</form>";
and the error I get says:
'repetition-operator operand invalid' from regexp.
I was hoping to make that SELECT into a subselect for an update query but I'm stuck at this point.
I think your problem is in your form expression. Try the following:
"<form[^>]*>.+?</form>"
Remember that MySQL supports a limited set of regular expression matching and testing.
See this document.