Mysql regexp to get right table names from database schema [duplicate] - mysql

This question already has an answer here:
How to match a fixed string ending with a number using regex [duplicate]
(1 answer)
Closed 2 years ago.
I'm trying to select, from mysql, some specific tables that matches a pattern.
The specific pattern I'm looking for is like 'my_table_number'. For example, my_table_436814 or my_table_35413. The thing is that there are other tables that looks like my_table_old_14353 or my_table_351434_times. I just want to filter out the ones that are my_table_number.
I have tried different patterns, but failed to get what I really need.
The most closest approach was with this:
select table_name from
information_schema.columns ca
where ca.table_name REGEXP '[0-9]$'
How can I achieve what I'm looking for?

Use
REGEXP '^my_table_[0-9]+$'
See proof
NODE
EXPLANATION
^
the beginning of the string
my_table_
'my_table_'
[0-9]+
any character of: '0' to '9' (1 or more times (matching the most amount possible))
$
before an optional \n, and the end of the string

Related

Find ID in string of IDs separated with comma [duplicate]

This question already has answers here:
MySQL query finding values in a comma separated string
(11 answers)
Closed 1 year ago.
I would appreciate help with one regex.
I have a string of ids example "123,55,68,890,456,333,168"
How should the regex look like to find a specific id -- example 68? Bear in mind that 168 shouldn't be returned.
There are four cases where the id could be positioned:
x (only one id in the list/string)
,x, (somewhere in the middle of the string)
x, (at the beginning of the string)
,x (at the end of the string)
I would use this regex as part of the SQL query.
Thanks in advance
/(?:^|,)number(?:$|,)/ should do the trick.
(?:) is a non-capturing group. It looks for the value in the parentheses after the :, but doesn't include it in your result.
So this regular expressions says "Find number that is at the beginning or preceded by a comma, and at the end or followed by a comma."

How does "not regexp '^[aeiou].*[aeiou]$' " work? [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
The question is to 'query the list of CITY names from STATION that either do not start with vowels or do not end with vowels.' But the not here should work as "and" instead of "or"?
The problem is stated as "NOT(starting with a vowel) OR NOT(ending with a vowel)". The sql expression is saying "NOT(starting with a vowel AND ending with a vowel)", which is equivalent: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
...except that the sql expression will produce the wrong result for city names that are just a single vowel character, because the regex will only match values when there are at least two characters.
You regex should be
(^[aeiou])|([aeiou]$)
Right now regex will only match if it start and ends with a vowel, while you want to say, start with vowel and it doesn't matter what is after, or it doesn't matter what is at the begining as long as it ends with a vowel.

REGEXP in MYSQL isn't working for full word search all time [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
What is a word boundary in regex?
(13 answers)
Closed 2 years ago.
I've a table like this,
values
-------------------
male,female
PHP 30
PHP (30)
PHP ($30),CSS ($20)
PHP {$30},CSS {$20}
PHP [$30],CSS [$20]
PHP (€30),CSS (20)
I've prepared the sql like this,
SELECT mytable.values FROM mytable WHERE mytable.values REGEXP '[[:<:]]PHP ($30)[[:>:]]'
It should match one row (4th), but it's not working.
It's also not working with
() / {} / [] or any types of symbols like $ / €
I want to mention here that,
MYSQL LIKE isn't the right thing for me I think, because it won't work if we want to match male.
REGEXP is working for PHP 30 here and it's working for only strings.
Could anyone please inform me what will be the best solution to match the exact word or sentence?
Thanks in advance.

Is there any function in MySQL for Regex Replace? [duplicate]

This question already has answers here:
How to do a regular expression replace in MySQL?
(13 answers)
Closed 6 years ago.
I have a table which needs stores some name and i need to replace a few characters before comparing them with another string
For instance, My table data is
abc
ghi:dki
ioe dsa
i read a string from user, which is of the form abc, ghi-dki, ioe-dsa. ie, all blankspaces, multiples spaces and symbols are converted to a hyphon(-). Now i need to compare. something like
SELECT MYCOLUMN FROM MYTABLE WHERE {Converted MYCOLUMN} = 'ghi-dki'
Can someone help me for figuring out which MySQL function can do it?
You can't do a regex replace in MySQL, but you can do a match.
SELECT mycolumn FROM tablename WHERE mycolumn REGEXP Replace('ghi-dki', '-', '^[\s:_-]*$');
Note: I didn't completely fill out the symbols character set, you'll have to add whatever you're using.

mySql - find non-Ascii character in html [duplicate]

This question already has answers here:
How can I find non-ASCII characters in MySQL?
(10 answers)
Closed 9 years ago.
I'm trying to find all non-asci characters I have in my DB in a specific table and column. In that column are stored Html description, and in some of them I've exotic or non-existing characters (for example: Hà¶ganà¤s ).
I'm triyng to match them with this query:
SELECT * FROM project_version WHERE description REGEXP '[^()\x00-\xFF\,\.-\<\>="\' /:;&=]'
But I think I'm missing something, cause it returns all of my records. Does anyone any advice?
Thanks in advance
Try moving hyphen to start or end otherwise it needs to be escaped also ^ will be treated as literal ^ in character class:
SELECT * FROM project_version WHERE description REGEXP '[()\x00-\x7F,.<>="\' /:;&=-]'