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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:41:03+00:00 2026-05-14T19:41:03+00:00

Edit: To be clear, please understand that I am not using Regex to parse

  • 0

Edit: To be clear, please understand that I am not using Regex to parse the html, that’s crazy talk! I’m simply wanting to clean up a messy string of html so it will parse

Edit #2: I should also point out that the control character I’m using is a special unicode character – it’s not something that would ever be used in a proper tag under any normal circumstances

Suppose I have a string of html that contains a bunch of control characters and I want to remove the control characters from inside tags only, leaving the characters outside the tags alone.

For example

Here the control character is the numeral “1”.

Input

The quick 1<strong>orange</strong> lemming <sp11a1n 1class1='jumpe111r'11>jumps over</span> 1the idle 1frog

Desired Output

The quick 1<strong>orange</strong> lemming <span class='jumper'>jumps over</span> 1the idle 1frog

So far I can match tags which contain the control character but I can’t remove them in one regex. I guess I could perform another regex on my matches, but I’d really like to know if there’s a better way.

My regex

Bear in mind this one only matches tags which contain the control character.

<(([^>])*?`([^>])*?)*?>

Thanks very much for your time and consideration.

Iain Fraser

  • 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-14T19:41:03+00:00Added an answer on May 14, 2026 at 7:41 pm

    Regex isn’t the tool for this, but you can use lookbehind and lookahead to match 1 in a tag. Here it is in Java, modified to have finite lookbehind (since Java doesn’t support infinite length lookbehind).

        String s = "123 <o123o></o1o1> <oo 11='11x'> x11 <msg136='I <3 Johnny!11'>";
        System.out.println(
            s.replaceAll("(?<=<[^<>]{0,999})(?=[^<>]+>)1", "")
        ); // prints "123 <o23o></oo> <oo ='x'> x11 <msg136='I <3 Johnny!'>
    

    There are many cases where this will fail, but it should get you started somewhere.

    See also

    • regular-expressions.info/Lookarounds

    Okay, I’ve “generalized” the problem so that it’s not HTML related. Here’s a snippet of Java that uses regex to remove [aeiou] from portions of a sentence enclosed by < and >, whose usage is reserved only to mark these special portions.

    BEWARE: this regex is absolutely unreadable. But yes, it works. And it uses no lookbehind, too.

    String s = "Wait <whaaat?> does this <really really> work???";
    System.out.println(
        s.replaceAll("(?!>)(?:(?=<)|(?=\\G)(?!^))(?:(?:(?![aeiou])(.))|.)", "$1")
    ); // prints "Wait <wht?> does this <rlly rlly> work???"
    

    I might try to explain it if there’s interest, but otherwise I’d suggesting using a simple loop like this instead:

    allocate output buffer
    set isInside := false
    for every character ch in input
       if (ch is openChar)
          isInside := true
       else if (ch is closeChar)
          isInside := false
       else if not (isInside and ch is control)
          append ch to buffer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT: See my answer below--> I am wanting to have a view that when
EDIT: iam using ajax to load text in my content that is why onload
OK, I'm not entirely clear how to ask this question, so please feel free
EDIT 1 : I think I was not clear myself before and hence could
i have to make a notepad where i write,edit,clear the text. this notepad need
EDIT: Just to make things clear, this problem was caused by a typo in
I have to edit my question just to make it clear. What I need
Edit (updated question) I have a simple C program: // it is not important
Edit : Note that, as Daniel and latkin noted in an answer and a

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.