TRIM to remove Prefix and Suffix from a string

TRIM() removes spaces from both ends by default and can also remove a specified leading or trailing string. See LTRIM() and RTRIM() for one-sided whitespace removal.


MySQL Trim
SELECT TRIM( BOTH 'XX' FROM 'XXplus2net.comXXX') -- Output plus2net.comX
Arguments
BOTH
Remove matching string from trailing and leading part of the string
LEADING
Remove matching string from leading part of the string
TRAILING
Remove matching string from trailing part of the string
SELECT TRIM(BOTH 'XX' FROM 'XX.plus2net.com.XXX') -- Output .plus2net.com.X
SELECT TRIM(LEADING 'www.' FROM 'www.plus2net.com') -- Output plus2net.com
SELECT TRIM(LEADING 'XX' FROM 'XX.plus2net.com.XXX') -- Output .plus2net.com.XXX
SELECT TRIM(TRAILING 'com' FROM 'plus2net.com') -- Output plus2net.
SELECT TRIM(TRAILING 'XX' FROM 'XX.plus2net.com.XXX') -- Output XX.plus2net.com.X
Without using any arguments we can remove blank space from both ends of the string.
SELECT TRIM(' plus2net.com ') -- Output is plus2net.com

Normalizing case before TRIM()

If you need predictable case-normalized trimming, apply UPPER() or LOWER() consistently to the removal string and the source string.

SELECT TRIM(BOTH 'XX' FROM 'xx.plus2net.com.XXX') -- Output xx.plus2net.com.X
For normalized case handling, see LOWER() and UPPER().
SELECT TRIM(BOTH UPPER('XX') FROM UPPER('xx.plus2net.com.XXX')) -- Output  .PLUS2NET.COM.X
By using LOWER
SELECT TRIM(BOTH LOWER('XX') FROM LOWER('xx.plus2net.com.XXX')) -- Output .plus2net.com.x 





Subscribe to our YouTube Channel here



plus2net.com

18-12-2023

SELECT TRIM(BOTH LOWER('X.mcoX') FROM LOWER('xx.plus2net.com.XXX')) // Output plus2net




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer