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 8186197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:06:45+00:00 2026-06-07T02:06:45+00:00

I have the following example string and I would like to remove only one

  • 0

I have the following example string and I would like to remove only one set of zeros.

The example string is

AAL000007200100000787777388300000

I would like to remove only the first set of zero’s and leave the rest intact. I want to end up with

AAL7200100000787777388300000

I have tried the following but it is always too greedy and takes the second set of zeros as well!

#!/usr/bin/env python3
import re

suffixdrop = re.split("\B0+\B", "AAL000007200100000787777388300000", re.I)
if suffixdrop: #found a suffix here
        print(suffixdrop)

The result of the print is

[‘AAL’, ’72’, ‘100000787777388300000’]

  • 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-06-07T02:06:46+00:00Added an answer on June 7, 2026 at 2:06 am

    \B matches the opposite of word boundaries, which doesn’t sound like what you want here.

    If you want to remove the first set of consecutive 0’s after a non-digit character, try this:

    In [7]: print x
    AAL000007200100000787777388300000
    
    In [8]: print re.sub("^(\D+)0+", r"\1", x)
    AAL7200100000787777388300000
    

    re.sub("^(\D+)0+", r"\1", x) means “match the start of the line followed by any number of non-digit characters, followed by any number of 0 characters” and replace it with the first group of non-digit characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string indexed array that I would like to remove an item
Take the following example, I have a class public class SomeItem { public string
Following is the example I have reproduced: charName :: Char -> String charName 'a'
I have following example string that needs to be filtered 0173556677 (Alice), 017545454 (Bob)
I have an input string that's generated as in following example: string.Format(Document {0}, was
I have following example string: $0$aaaaa$1$bbbbb$2$cccccc where between dollar markers there are some numbers.
I have the following, which makes an xmlNodePtr and then I would like to
I have the following tables Pedal Brand:string Classification:string Model:string Variety Title:string name:string pedal_id:integer Example
I'm trying to figure out how XSLT process namespace prefixes and have following example:
We have the following example in node.js var http = require('http'); http.createServer(function(request, response) {

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.