How i can remove
src="../assets/default/js/jquery-1.4.2.min.js"
from this line
<script type="text/javascript" src="../assets/default/js/jquery-1.4.2.min.js">
using regex?
How i can remove
src="../assets/default/js/jquery-1.4.2.min.js"
from this line
<script type="text/javascript" src="../assets/default/js/jquery-1.4.2.min.js">
using regex?
You didn't specify a regular expression dialect, but this one should work in most:
src=".*?"
Though I need to preface this with the usual disclaimer about parsing HTML with regex, the following should work for input strings very similar to the example you gave:
/src=(["']).*?\1/
You didn't say what regex language you're using, but replace whatever matches the above pattern with an empty string.
The main advantage of this version is that it will accept both src="..."
and src='...'
, but not src="...'
or src='..."
. It also won't be thrown off by stuff like src="...foo='bar'..."
, although that's unlikely to come up.
If you're doing this to prevent linking to external scripts, don't. It won't work.
src="…"
attributes (legal according to the spec? I doubt it; does it work? I bet), browser parsing bugs, etc.You'll get to look forward to:
<!-- this is even in-spec, except for the made-up attributes fakeout and oops.
a trivial out-of-spec bit of fun: what happens if we drop the final quote?
I bet browsers would still figure it out. -->
<script type="text/javascript" fakeout="src=" oops="" src
="http://example.com/oops.js">
document.write("<script sr" + 'c="http://example.com/oops.js"></script>");
</script>
Now, if instead you're just trying to find all the externally-referenced scripts in a site you maintain (e.g., to see if a random script is still used), then many of the other answers will do.
Here's my stab at it:
s/\s*src="[^"]*"//
That one also removes any whitespace before the 'src' (via the '\s*').
Solution using sed
sed 's/\(^.*\) src.*/\1>/'
<script type="text/javascript">