Questions tagged [regex]

The term REGEX is a shortening of the phrase "regular expression". A regex is typically a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings.

Filter by
Sorted by
Tagged with
1
vote
1answer
19 views

Count numbers in scientific notation (E-notation)

I'm trying to check if a part number field has scientific notation values and came up with this simple solution: SELECT count(*) as overall, count(*) filter (where partnumber ilike '%E+%') as ...
3
votes
1answer
75 views

Convert column value stripping html tags into sql view with rows and columns

I have a table named data with a column pid & display_data. Pid is the serial number of all rows. The value of display_data column is as below : For each row display_Data has values in the format =...
0
votes
1answer
54 views

SQLite, ASCII Characters 0x20 to 0x7E Check Constraint

I have the following table which I'm trying to limit the column name to ASCII characters ranging from 0x20 to 0x7E. Why is it not working? CREATE TABLE test ( id INTEGER NOT NULL, name TEXT ...
-2
votes
1answer
45 views

oracle find to first hyphens after last vertical bar

oracle find to first hyphens after last vertical bar using REGEXP_REPLACE SELECT REGEXP_REPLACE ('sadsa|dd|g - g|hh|yyyyy - tttt - ooo', '.*(\|)(?!.*\|).*?\-{1}', '' ) FROM dual; string input '...
0
votes
0answers
26 views

How to check if a string contains a sequence of binary regexp chars in postgres

I am trying to filter all non-UTF characters in a field of a table in postgres. It looks to me that I need to filter anything that is not: $$[\09\0A\0D\x20-\x7E]|$$|| -- ASCII $$[\xC2-...
1
vote
0answers
29 views

MariaDB REGEXP_REPLACE Invalid utf8 byte sequence

I'm working with a fairly old (15 years) old database. It started as a MySQL3, was upgraded several times, the frontends had problems with proper encoding, the whole database was converted to utf8mb4 (...
4
votes
2answers
627 views

Is there an operator or an easy way to match an expression one or more times with the LIKE operator in SQL?

For example if I run the following query, the expression in the WHERE clause will only match on the first letter before a number but is there a way to match on one or more letters first (e.g. in the ...
0
votes
1answer
24 views

How to select any couple of digits except '00' using mysql regex subset syntax?

I just found out that mysql doesn't support full regular expressions syntax. I have to select any couple of digits except of 00 (so, 11, 54, 02, are ok, but not 00). Normally I would use a negative ...
0
votes
1answer
28 views

How to query mysql tables with regular expressions?

I'm using a correct regex, already tested with other tools. But in mysql seems not to work properly. Say this data: And I want to select all the records which start with 2 non-digits followed by a ...
0
votes
1answer
31 views

Using to_base64 function and regexp_replace with backreferences in MariaDB

I am using MariaDB 10.3. I want to replace a string using REGEX and encode part of the result into base64. For example, I want to first invert the "a" and "b" strings in this example: MariaDB [(none)...
0
votes
1answer
236 views

Date pattern regex doesn't match the records in PostgreSQL query?

I am working with a dataset in PostgreSQL which is quick messy. I have written a few regex operations to find date patterns in the records of a table. Since I don't have a generalized REGEX defined ...
2
votes
0answers
88 views

check if MySQL is using the Henry Spencer implementation for REGEX

Prior to MySQL 8.0.4, MySQL used the Henry Spencer implementation for REGEX and you could use this for word boundaries: '[[:<:]]' and '[[:>:]]' From 8.0.4 MySQL is using the ICU implementation ...
0
votes
1answer
61 views

Need help with Regex in SQL Server query editior

I have a file with thousand lines of codes with index details like below: IF NOT EXISTS (SELECT 1 FROM SYS.INDEXES WITH (NOLOCK) WHERE name = 'IX_Test1' AND [object_id] = OBJECT_ID(N'Test1', N'U')) ...
3
votes
2answers
329 views

Convert Ruby regex to Postgres regex, for selecting invalid email addresses

I've done some internet trawling, and some reading of the Postgres regex docs, but I'm at the stage where I think asking a question here is the best thing to do. I have the following Ruby regex: /\A[...
0
votes
1answer
151 views

Cleaning up bad data with REGEXP_REPLACE too aggressive with non latin chars

Trying to use REGEXP_REPLACE to cleanup a text field in a table. Here's my query: select title original ,REGEXP_REPLACE(title, '[^a-zA-Z0-9]+', ' ') clean from tmp_table2 WHERE txn_title like '%?%' ...
2
votes
1answer
2k views

SQL regex to identify alphanumeric values

I am trying to exclude values like 3708.DK in sql. I'm using pattern like LIKE '%0-9.%' and '%[0-9.A-Z]%' and its not working . Please suggest.
0
votes
1answer
615 views

Regex replace with empty string results in NULL characters in between

Replacing a character with regexp_replace results in NUL characters in between. SELECT REGEXP_REPLACE(aColumn,'c', '') INTO OUTFILE 'Replaced.csv'; for abcd results in: ab d (infact: abNULd) This ...
1
vote
1answer
290 views

Mysql Regex on where clause

I need a regular expression which will give me only those records which match a pattern.Below is table structure auto_id (Auto-increment) | json_string (Text) Sample records are: auto_id | ...
0
votes
1answer
761 views

Using Regex in mySQL query

I have a database column with multiple names separated by line breaks like this: jones, sue jones, mark I want to generate a query that keeps the first line and discards the rest, no matter how many ...
-1
votes
3answers
797 views

how to regexp positive lookaheads in MySQL

I want to filter as regexp like "(?=nkf)(?=bom)" in MySQL. This example regexp works in PHP, JavaScript and other. This regexp means both words include "nkf" and "bom". I try the regexp in WordPress ...
1
vote
1answer
337 views

How to clean every non-digit except the + at beginning of string with regexp_replace in Postgresql?

Related to a comment, I would like to find a way to clean with regexp_replace in PostgreSQL any non-digit except the + at beginning of the string. For example +(7)9125415501 shall become +79125415501
0
votes
1answer
522 views

Oracle regular expression replace in string ignoring first and last characters

regular expression replace in string ignoring first and last characters if they matched my try SELECT REGEXP_REPLACE ('TLYU TK0T23T', '[^(\A.)]T[^(.\Z)]', 'Qq' ) contain FROM dual; result ...
2
votes
2answers
3k views

Postgres - Return default value if regex match fails

I'd like to attempt a regex match, and return null if it fails. The following query attempts to find the first number in a string. The result ignores the entry with text 'blah'. I'd prefer it to ...
0
votes
2answers
490 views

SQL Regex String Matching of Two Words

I'm trying to write a query to show the rows containing a code that begins with 11-digit number followed by -1 or -2 then _DataSheet or _RoHS Examples 02704198976-1_DataSheet 03448106681-1_RoHS ...
5
votes
2answers
1k views

Capitalize first letter with exceptions

I need to properly format some European addresses. One of the steps is to capitalize the first letter, but avoiding some specific words, like 'on', 'upon', 'von', 'van', 'di', 'in', 'sul'. Therefore, ...
19
votes
3answers
2k views

What is it called when you search the middle of a string instead of the beginning?

I am trying to polish up my vocabulary to better communicate with my fellow developers. We have several places in the site where we are debating if we should search for a string from the beginning '...
1
vote
2answers
147 views

SQL regex PostgreSQL

Let's consider a table like that: id | name 1 | This is a test sentence 2 | is a sentence TeST 3 | This a IS test sentence 4 | iS a tEst sentence tHis 5 | This a test sentence is How ...
0
votes
1answer
211 views

Problem to apply replacement with regexp that include look ahead in Postgres

I have this kind of string 12s2-3a abc def and I am trying to apply the regexp ^(?=.*\d) to remove the first part and having as left abc def. I have tried with: select substring ('12s2-3 abc def' ...
1
vote
1answer
116 views

Why is LIKE producing different results than my regex?

Using Postgres 9.5. Having some trouble using regular expressions to find matching rows. I tried select * FROM my_object_times t where t.name ~ '/\(.*\)\s*$/' ... (0 rows) which returned no rows, ...
1
vote
1answer
1k views

REGEXP in a where clause

I store s3 bucket's path for files in my database. Files can be either pictures(jpg) or pdfs. Let's suppose I have uploaded photo.jpg to my database via application, path will be like: /{s3bucket}/...
16
votes
1answer
12k views

Querying non-ASCII rows from Postgres

Does [:ascii:] class work in Postgres at all? It is not listed in their help, however I see examples in the web which utilize it. I have a UTF-8 database, where collation and c_type are en_US.UTF-8, ...
3
votes
3answers
3k views

SQLite, ASCII A-Z Check Constraint

I have the following table which I'm trying to limit the column "prefix" to ASCII alphabetical characters. However, I am still able to insert other characters after using the following constraint. Why ...
0
votes
1answer
413 views

Display a field using regex

I have a table with a field in with data such as: id | path 1 | /2/9/1 2 | /2/4/11 3 | /1/3/11 4 | /5/3/2 5 | /2/1/4 I'm wanting to do a select query to show only the first number between ...
4
votes
1answer
3k views

Repeating pattern X amount of times in LIKE

I took a look at the documentation for patterns from Microsoft (can be found here), and from what I understood, it doesn't say a way for a pattern to repeat a limited number of times. It's either the ...
1
vote
2answers
1k views

How to use character classes in a Postgres regex select?

I'm trying to create a query that selects strings that contain the number 21, without hitting strings such as 210 or 121. My efforts below have shown my progress, in that I've managed to apply a ...
1
vote
1answer
2k views

Oracle index with REGEXP_REPLACE is it a good idea?

I have a table of contacts with 1 million registers and now the user wants to search in it by the telephone. Trying to avoid a fullscan I decided to create a new index in this column, but the trick ...
2
votes
1answer
561 views

REGEXP does not show the right result?

I have in the name column: 3 boxes of frogs 7 boxes of frogs 48 boxes of frogs When I execute: SELECT name FROM items WHERE name REGEXP "[^1-5] boxes" ...the result is: 7 boxes of frogs 48 boxes ...
0
votes
1answer
37 views

Create new table values based on partial column value - access

I am trying to remove a ton of unnecessary rows in this table. Currently there are 1.3m of them which are all an individual transaction id - with the country and destination assigned for each which ...
2
votes
2answers
9k views

How to use LIKE with subquery?

In a SQLITE3 DB, I have a table A with a column 'word' containing search words that partially match a column in another table B. I'd like to SELECT all rows FROM table B WHERE B.name LIKE %...
3
votes
2answers
2k views

Update fields that contains certain prefix by lookup table

I have a temporary table #NAMEOLD_NAMENEW which contains a column NAMEOLD and a column NAMENEW where every row contains the old and new value of a value to be updated. This table consists of roughly 2....
2
votes
1answer
5k views

Unicode error with \u0000 on COPY of large JSON file into Postgres

I'm using Postgres 9.4 on Ubuntu 14.04. I have a 30GB JSON file that I'm trying to COPY into Postgres. But I keep getting the following error: COPY <table>(comment_jsonb) FROM '<json file&...
1
vote
1answer
156 views

Using REGEX_LIKE to Implement a Check Constraint

Background I am working on the database design for an application that tracks information about database development projects at my company. The project management office (PMO) assigns a psued-...
2
votes
1answer
2k views

Oracle: REGEXP_LIKE: Strings with angle brackets aren't found (whether they are escaped or not)

The following question will answer my original question, plus many others. What would the correct syntax be to do a REGEXP_LIKE search (in Oracle Database 12c) for this string (which exists somewhere ...
0
votes
1answer
502 views

Oracle: How to create secondary index based on every word in a CLOB

I have a Table where each record is made up of a VARCHAR2 and a CLOB. The VARCHAR2 is the primary key. There are currently 1.5 million records and growing. The table is only ever used for REGEX ...
2
votes
2answers
7k views

Oracle regexp_like square brackets inside character set

This questions is in regards to Oracle, pl/sql, and the regexp_like function. I am trying to build a character set that will match on all typical special characters. My character set currently looks ...
1
vote
2answers
827 views

PostgreSQL return word after matching first character

I would like to return the words beginning with ':' from 'select :barns, :fowl, :cows from farm' using regexp_matches. So far I have: select regexp_matches('select :barns, :fowl, :cows from farm', '(...
3
votes
2answers
5k views

How to split numbers and text in MySQL

I have searched over the internet looking for a function like REGEXP_REPLACE in Oracle, regexp_replace in PostgresSQL but I haven't find one similar in MySQL just REGEXP and RLIKE, but these operators ...
0
votes
2answers
3k views

Faulty oracle11g regexp_replace on removing duplicates

I have a comma separated list of values (as one single string), which contains duplicates, and I want to remove them. I tried with REGEXP_REPLACE but for certain values it gives me a wrong result: /* ...
0
votes
1answer
7k views

Postgresql regex match all digits in column

How do I extract all digits from a string with regex in pgsql? select regexp_matches('dsa8a552a5a2a5?', '\d+'); Will output only 8. Need to get 8552525
2
votes
1answer
632 views

How To Exclude Queries Returned From mysqldumpslow Command

I would like to ignore queries in the mysql-slow log that originate from running the command mysqldumpslow by using SQL_NO_CACHE as the trigger word. My experience using regex are limited at best and ...