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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:05:28+00:00 2026-06-16T13:05:28+00:00

I have a string/column something like this String a = 000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF; I

  • 0

I have a string/column something like this

String a = "000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF";

I want to create a substring which doesn’t have the part ' x3A 973911' in it.

Whic means I want something like this,

000003023_AggregateStopLossLimit_W_2012-12-22.PDF

There is a list of such strings which will have different values but the format will be the same. I want the part of string to be removed which comes after the first space and ends at the next ‘_’.

This is what I have done already, this is working fine, but want to know if there is a better way of doing it.

String b = a.replaceAll(a.substring(a.indexOf(" "), a.indexOf("_",a.indexOf(" "))),"");

It would be even better if I can do this in db itself, which is oracle, instead of in java. Any idea to get this formatted string from the column directly using select?

One more requirement, I dont want to display the extension of the file.
So nothing after the ‘.’ should be displayed, which means something like this '000003023_AggregateStopLossLimit_W_2012-12-22'
I tried the following using the previous solution of APC

 select regexp_replace ( your_string
                          , '([^[:space]]*) (.*)_(.*)....'
                          , '\1_\3') as new_string from your_table

This is working fine for now.
This should be removing last 4 characters and have the risk of not getting proper result if the extension is more or less than 3 or if the string is not truncated.
I’m looking for a more aesthetic way to do it.
Any chance?

  • 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-16T13:05:29+00:00Added an answer on June 16, 2026 at 1:05 pm

    To do it in the database:

    select regexp_replace ( your_string
                             , '([^[:space]]*) (.*)_(.*)'
                             , '\1_\3') as new_string
    from your_table
    

    Unfortunately Oracle doesn’t have any syntax to enforce laziness (non-greediness) in its regex implementation. That’s why my original ‘(.*) ‘ included the x3A: it matched up to the last space with a following underscore. However, the negation syntax will isolate the string up to the first space.

    “The ‘_’ after W is missing. Any chance to get that also?”

    You can format the replacement string anyway you want. The easy way out is to do what I have done, and hardcode the underscore between the two matched patterns. Alternatively you could make it a search pattern in its own right and include it in the replacement string (although you’re more more likley to do that for more complicated searches).


    Oracle introduced Regular Expressions in 10g; the functions are covered in the documentation. The regex implementation is POSIX compliant, so it lacks some of the functions you might have come across in say Perl. The Regex support is detailed in an appendix to the SQL ref.

    As for tutorials, well I have a much-thumbed copy of the O’Reilly pocket book; I was given my copy at Open World 2003 but the ebook is reasonably priced. Buy it here. Anotgher good starting point is a series of threads by cd on the OTN forum: start reading here.

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

Sidebar

Related Questions

I have a Nx4 cell array in Matlab which looks something like this: id1
I have a 3 column data frame which looks a little like this: id
I have strings like the ones below in a SQL column. I want to
I have to get the month from a column which stores string in format
I have a class like this: private class MyClass { [DisplayName(Foo/Bar)] public string FooBar
I have a SQL*Loader control file that has a line something like this: FIELDS
I have a variable like: Collection<Map<String, String>> allFieldValues; In this variable I have all
I want to do something like this: @Entity public class Bar { @Id @GeneratedValue
I have a string column (Col1) in table (Tab1). I want to write a
I have date stored as string in an sqlite database like 28/11/2010. I want

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.