We help IT Professionals succeed at work.

Notepad++ REGEX (delete * between DIV tags, multiple lines)

1,901 Views
Last Modified: 2012-08-13
Here's what I have..

<script type="text/javascript">
sflkjasdfkjsafsf sdf sdf sdf sdf sd f
sjd ssdf fsf sdf sdf sdf sdslfjsklfjsdlkfjs
dfsf sf sfd sf sdf
dflksdfjklsdf sdd s
sdkfsdklsd sdf sdfs df f sjfsdklfsdf
</script>

I'm trying to delete everything between the scripts.. So all I'm left with is this..

<script type="text/javascript"></script>


Is there someway to delete * between <script type="text/javascript"> and </script>?
Comment
Watch Question

oh sorry I'm using

NOTEPAD++

it has a find and replace regex feature.
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
I had a go at this using notepad++, and it's not trivial. It's not great at matching multiple lines.

Do you need to do this just once, or on an ongoing basis? You might be best using a different tool, depending on your answer
well I need it every now and then... if there is a php-based regex solution I can use that too.  I have a directory of files that I need to run it on.
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
PHP is ideal. If you can read the file into a variable, it should be as simple as this:

$html = (the contents of your file)

$pattern="@(<script type=\"text/javascript\">).*?(</script>)@s";
$replacement="$1$2";
$fixed_html = preg_replace($pattern, $replacement, $html);
Awesome, but how would I go about saving the file after that change and opening all the files in a directory?
Web Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Thanks for all the help, can you shoot me a sample script that preforms the whole tamale?



I'll try it on my windows machine and if it doesn't work I'll use my linux server just in case.
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011

Commented:
Sorry, I don't have time today to put that all together. I'm happy to help with any issues if you give it a go though.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.