9.11 Extract a string according to regular expression
Extract a string from a sequence of strings according to a regular expression.
One task is to remove all comments (data enclosed in ) from an html file. Below is part of the file:
<html>
<!-- Row Highlight Javascript -->
<script type="text/javascript">
window.onload=function(){
var tfrow = document.getElementById('tfhover').rows.length;
var tbRow=[];
…
};
…
</html>
In SPL, s.split(d) function works with @r option to get this done. Parameter d is a regular expression.
SPL script:
A | |
---|---|
1 | =file(“table.html”).read() |
2 | =A1.split@r(“<!--.*-->”) |
3 | =A2.concat() |
4 | >file(“table.html”).write(A3) |
A1 Read in the html file.
A2 s.split() function uses @r option to extract the string according to the specified regular expression.
A3 Concatenate parts of the extracted string to get an html format string without comments.
A4 Write the result string to a file.
Execution result:
Value |
---|
<html><script type=“text/javascript”>window.onload=function(){… |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL