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

The Archive Base Latest Questions

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

I have a function in my script that’s supposed to take in a string

  • 0

I have a function in my script that’s supposed to take in a string of HTML and return the same string with the exception that all the elements shall have been changed to one that is 2 levels higher (ie. h1->h3, h2->h4 etc.). This of cause needs to work independed of casing, and it must not remove attributes, however, I’m not about to use a full html-parser for it either, as it’s a fairly simple task, so I figured I’d go about this with regexes. The problem is (me beeing fairly new to vbscript and all) that I don’t know how to achieve the desired effect.

What I have currently is this:

Function fiksoverskrifter(html)
   Dim regex, matches, match
   Set regex = New RegExp
   regex.Pattern = "<(/?)h([0-9])(.*?)>"
   regex.IgnoreCase = True
   regex.Multiline = False

   fiksoverskrifter = html

   Set matches = regex.Execute(html)
   For Each match in matches

   Next

   Set regex = Nothing
   Set matches = Nothing
   Set match = Nothing
End Function

What I want inside the For Each-loop is simply to swap the numbers, however, I’m not sure how to do that (I’m not even sure what properties the match-object exposes, and I’ve been unable to find it online).

How should I complete this function?

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

    You’re asking for pain trying to do this with regex (not so much the replace but the fact that it’s an increment with a single regex pattern), if it’s only a case of replacing the Headers, i’d use replace():

    For i = 4 To 1 Step -1
        strHtml = replace(strHtml, "<h" & cstr(i), "<h" & cstr(i + 2), 1, -1, vbTextCompare)
        strHtml = replace(strHtml , "</h" & cstr(i), "</h" & cstr(i + 2), 1, -1, vbTextCompare)
    Next
    

    (HTML Spec is only valid for H1–H6 – not sure if you want to ignore H5 & H6)

    If you want to stick with the regex option, i’d suggest the use of regex.replace()

    I know in JavaScript you can pass the matched pattern into a function and use that function as the replacement, exactly what you would need here – but i’ve never seen this done in VBSCRIPT, example:
    Use RegExp to match a parenthetical number then increment it

    Edit 1:

    Found the reference to the matches collection & match object:

    http://msdn.microsoft.com/en-us/library/ms974570.aspx#scripting05_topic3

    So, you could read the match from the match.value property, but you’d still need to resort to a 2nd replace i think

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

Sidebar

Related Questions

I have a function in a powershell script that is supposed to untar my
I have a function in java script, that I used it to take the
I have a java script function that i have called on body load mousemove()
I have a bash script that has this function in it: function start_vi() {
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have a script that looks like this #!/bin/bash function something() { echo hello
I have a PHP script that I'm calling with the .post() function in jQuery.
I have a python function that makes a subprocess call to a shell script
I have a jquery-ajax function that sends data to a php script and the
I have this simple code that speaks for itself. <script language='javascript"> function check() {}

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.