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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:03:42+00:00 2026-05-15T02:03:42+00:00

I have the following string: h3. My Title Goes Here I basically want to

  • 0

I have the following string:

"h3. My Title Goes Here" 

I basically want to remove the first four characters from the string so that I just get back:

"My Title Goes Here".  

The thing is I am iterating over an array of strings and not all have the h3. part in front so I can’t just ditch the first four characters blindly.

I checked the docs and the closest thing I could find was chomp, but that only works for the end of a string.

Right now I am doing this:

"h3. My Title Goes Here".reverse.chomp(" .3h").reverse

This gives me my desired output, but there has to be a better way. I don’t want to reverse a string twice for no reason. Is there another method that will work?

  • 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-15T02:03:43+00:00Added an answer on May 15, 2026 at 2:03 am

    To alter the original string, use sub!, e.g.:

    my_strings = [ "h3. My Title Goes Here", "No h3. at the start of this line" ]
    my_strings.each { |s| s.sub!(/^h3\. /, '') }
    

    To not alter the original and only return the result, remove the exclamation point, i.e. use sub. In the general case you may have regular expressions that you can and want to match more than one instance of, in that case use gsub! and gsub—without the g only the first match is replaced (as you want here, and in any case the ^ can only match once to the start of the string).

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

Sidebar

Related Questions

I have following string task BLABLA@{taskId} @{BLABLA.title} and want to extract all placeholders from
assume that I have the following obejct: class title { string Title; int id;
I have the following string: <h1 class=title>This is some heading?</h1><h2 class=desc>Here is the description
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull
Suppose I have the following Domain class: class Book { String title String author
I have the following string: <span class=ClassName @variable title=ClassName @variable>Variable Title</span> ClassName, variable &
I have the following code: public Map<String,?> createItem(String title, String caption) { Map<String,String> item
In my html I have <h2>Title goes here</h2> @using (Html.BeginForm(Action, Controller, FormMethod.Post, new {
I have a following class defined @JsonTypeName(PhotoSetUpdater) public class PhotoSetUpdater { @JsonProperty(Title) private String
I have an array of strings like this: Some Title##DD-MM-JJJJ##Some Text goes here##img1.jpg##img2.jpg I'd

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.