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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:39:32+00:00 2026-05-11T18:39:32+00:00

I have a bunch of html with lines like this: <a href=# rel=this is

  • 0

I have a bunch of html with lines like this:

<a href="#" rel="this is a test">

I need to replace the spaces in the rel-attribute with underscores, but I’m sort of a regex-noob!

I’m using Textmate.

Can anyone help me?

/Jakob

  • 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-11T18:39:33+00:00Added an answer on May 11, 2026 at 6:39 pm

    I don’t think you can do this properly. Though I wonder why you need to do it at one go?

    I can think of a really poor way of doing it, but even if I don’t recommend it, here goes:

    You could sort of do it with the regex below. However, you would have to increase the number of captures and outputs with a _ on the end to the potential number of spaces in the rel. I bet that is a requirement which disallows this solution.

    Search:

    {\<a *href\=\"[^\"]*" *rel\=\"}{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*{([^ ]*|[^\"]*)}( |\")*
    

    Replace:

    \1\2_\3_\4_\5_\6_\7_\8_
    

    This way has two downsides, one is there might be limitations to the number of captures you can have in Textmate, two is you’ll end up with a large number of _’s on the end of each line.

    With your current test, with the regex above, you would end up with:

    <a href="#" rel="this_is_a_test">____
    

    PS: This regex is of the format of the visual studio search/replace box. You’ll probably need to change some characters to make it fit textpad.

     {} => capturing group
    
      () => grouping
    
      [^A] => anything but A
    
      ( |\")* => space or "
    
      \1 => is the first capture 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have html code like this <tr class=odd> <td><b>Reason for Termination:</b></td> <td>this has bunch
I have a HTML/CSS File laid out with a bunch of areas that need
so I have this HTML table with a bunch of big numbers in it
ok, so i have this slideshow.html containing just a bunch of pictures, and the
I have a bunch of inline-block elements over several lines which I'd like to
I have a bunch of html that has no line breaks. I would like
If I have a bunch of text, let say HTML, but it doesnt have
I currently have a bunch of lines that look like: txt = Can't print
I have a bunch of html files and need to convert and format them
We have bunch of Domain Entities which should be rendered to an html format,

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.