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

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.

Related

Wildcard Search in MySQL, LIKE '%string%' (Fiddle) [duplicate]

This question already has answers here:
MySQL: is a SELECT statement case sensitive?
(14 answers)
Closed 1 year ago.
I want to search data with condition name = '%Park%'
this is my sample code in Fiddle.
http://sqlfiddle.com/#!9/d0e059/12
when I tried in BigQuery, It returns case sensitive result.
data exactly match with 'Park'. not 'PARK','park'
But in mySQL test which I linked,
it returns all alphabetic 'Park' contains 'PARK','park'
(no case sensitive)
Does mySQL originally NO CASE SENSITIVE EVEN IN DATA?
Or did I go wrong in something??
For case in MySQL you can use LIKE BINARY;
SELECT name, host_name, borough, district, price
FROM airbnb
WHERE name LIKE BINARY '%park%';
MySQL like binary

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

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

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.

Retrving data from MySql with case sensitivity [duplicate]

This question already has answers here:
How can I make SQL case sensitive string comparison on MySQL?
(12 answers)
Closed 8 years ago.
I have a Login table in MySql database . . In table there is a column by cname and one of the value is 'Raghu'. My question is when i write the query as
Select *from Login where cname='raghu';
Then it is retrieving the record which contains 'Raghu' . I want it to retrieve according to case . How can I retrieve with case sensitively, values in the data of tables.
Use: 10.1.7.7. The BINARY Operator
The BINARY operator casts the string following it to a binary string. This is an easy way to force a comparison to be done byte by byte rather than character by character.
Select * from Login where binary cname='raghu';
SELECT * from Login WHERE STRCMP(cname,'Raghu')=0;
Can you try this, you can use LOWER FUNCTION in either column name LOWER('cname') or in value LOWER('raghu');
Select *from Login where LOWER(`cname`) = 'raghu';

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,.<>="\' /:;&=-]'