Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 937263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:26:57+00:00 2026-05-15T21:26:57+00:00

For example, if all entries in a particular column have the form [a-z]+[0-9]+, how

  • 0

For example, if all entries in a particular column have the form [a-z]+[0-9]+, how can one extract just the leading letters, so that asdf123 and as3456 return ‘asdf’ and ‘as’, respectively?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:26:58+00:00Added an answer on May 15, 2026 at 9:26 pm

    This is not posible with mysql regex capablities (unless installing some udf’s which appear to be designed for that). Technically, as [0-9] is a limited set you could throw 10 LOCATE‘s in LEAST (watch out for & invalitdate 0), and use SUBSTRING. Not a pretty picture:

    SET @var ='asjdasd35433';
    SELECT SUBSTRING(@var,1,
      LEAST(
        IF(LOCATE(0,@var)=0,LENGTH(@var),LOCATE(0,@var)),
        IF(LOCATE(1,@var)=0,LENGTH(@var),LOCATE(1,@var)),
        IF(LOCATE(2,@var)=0,LENGTH(@var),LOCATE(2,@var)),
        IF(LOCATE(3,@var)=0,LENGTH(@var),LOCATE(3,@var)),
        IF(LOCATE(4,@var)=0,LENGTH(@var),LOCATE(4,@var)),
        IF(LOCATE(5,@var)=0,LENGTH(@var),LOCATE(5,@var)),
        IF(LOCATE(6,@var)=0,LENGTH(@var),LOCATE(6,@var)),
        IF(LOCATE(7,@var)=0,LENGTH(@var),LOCATE(7,@var)),
        IF(LOCATE(8,@var)=0,LENGTH(@var),LOCATE(8,@var)),
        IF(LOCATE(9,@var)=0,LENGTH(@var),LOCATE(9,@var))
       ) -1 ) as 'result';
    +---------+
    | result  |
    +---------+
    | asjdasd | 
    +---------+
    

    If you need it look at udf’s. Otherwise you’re just better of fetching the field and manipulate it outside MySQL.

    Edit: if the number fits in an integer, dirty hackery could result in :

    SET @var ='asjdasd35433';
    SELECT SUBSTRING(@var,1,LENGTH(@var)-LENGTH(CAST(REVERSE(@var) as UNSIGNED)));
    +---------+
    | result  |
    +---------+
    | asjdasd |
    +---------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using Qt and noticed that all the example class definitions have
To give you an example that you all should be familiar with, imagine that
Note that all the code is a simplified example in order to only communicate
I've been looking all over for a simple example of how to have an
I have a table that lists number of comments from a particular site like
Is there a tool that can let one browse relational data as a graph
I've a simple blog style system where a user can have many entries. I've
I have some huge log files I need to sort. All entries have a
Here is the requirement. I have a string with multiple entries of a particular
In my db I have a list of entries. Each one of the entries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.