Have a table:
| id | Name |
|----------------------|
| 1 |test1 test1 test1|
| 2 |test2 test2 test2|
Want to select 1st regex group (used 1st word to simplify), so my query:
SELECT regexp_replace(name, "^([[:alnum:]]+)[[:space:]].*$","$1") FROM table;
Result:
|test1 |
|test1test2 |
So how it comes that result is accumulated? And how to avoid it and still be able to use regex group?
UPD: Mysql version: 8.0.11, MySQL Community Server - GPL
regexp_replace(name, "(?s)\\s.*","")? If there must be at least 1 letter or digit before, useregexp_replace(name, "(?s)(?<=[[:alnum:]])\\s.*",""). Also, are you sure the replacement backreference syntax is a dollar+number? Try"\\1".