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

  • Home
  • SEARCH
  • 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 8741727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:22:03+00:00 2026-06-13T11:22:03+00:00

I am trying to extract javascript code from HTML content that I receive via

  • 0

I am trying to extract javascript code from HTML content that I receive via CFHTTP request.

I have this simple regex that catches everyting as long as there is no linebreak in the code between the tags.

var result=REMatch("<script[^>]*>(.*?)</script>",html);

This will catch:

<script>testtesttest</script<

but not

<script>
testtest

</script>

I have tried to use (?m) for multiline, but it doesn’t work like that.
I am using the reference to figure it out but I am just not getting it with regex.

Heads up, normally there would be javascript between the script tags, not simple text so also characters like {}();:-_ etc.

Can anyone help me out?

Cheers

[[UPDATE]]
Thanks guys, I will try the solutions. I favor regex because but I will look into the HTML Parser too.

  • 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-13T11:22:04+00:00Added an answer on June 13, 2026 at 11:22 am

    (?m) multiline mode is for making ^ and $ match on line breaks (not just start/end of string as is default), but what you’re trying to do here is make . include newlines – for that you want (?s) (dot-all mode).

    However, I probably wouldn’t do this with regex – a HTML parser is a more robust solution. Here’s how to do it with jSoup:

    var result = jsoup.parse(html).select('script').text();
    

    More details on using jSoup in CF are available here, or alternatively you can use the TagSoup parser, which ships with CF10 (so you don’t need to worry about jars/etc).

    If you really want regex, then you can use this:

    var result = rematch('<script[^>]*>(?:[^<]+|<(?!/script>))+',html);
    

    Unlike using (?s).*? this avoids matching empty blocks (but it will still fail in certain edge cases – if accuracy is required use a HTML parser).

    To extract just the text from the first script block, you can strip the script tag with this:

    result = ListRest( result[1] , '>' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extract the word need from this string. ctl00_ctl00_ContentMainContainer_ContentColumn1__needDont_Panel1 I have
I'm trying to write a code to extract some form data from a HTML
I have various HTML documents that I'm trying to extract the links to: (1)
I'm using the javascript code below trying to extract the number after gallery-entry_ in
I'm trying to extract a value through Javascript from an element's CSS3 attribute such
Trying to extract strings that are wrapped in double brackets. For example [[this is
im trying to extract some files from a jar-file downloaded using java-webstart. below code
I am trying to extract the page name from a complex url. This post
I'm trying to create a Javascript bookmarklet, which would extract a numeric ID from
I'm trying to extract a few rows from the table from this page http://www.money.pl/pieniadze/

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.