Link to home
Start Free TrialLog in
Avatar of www_puertoricoautoforo_com
www_puertoricoautoforo_comFlag for United States of America

asked on

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

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>?
Avatar of www_puertoricoautoforo_com
www_puertoricoautoforo_com
Flag of United States of America image

ASKER

oh sorry I'm using

NOTEPAD++

it has a find and replace regex feature.
Avatar of Terry Woods
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.
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?
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.