简体   繁体   中英

Removing characters outside of brackets

I'm new to html, and I need a quick and simple way to delete data outside of brackets, for example "abc [123] abc 115", which I would like to return: 123

I would like it to work with lists,

abc [123] abc 115
abc [1253] abc 112
cac [123] abc 115

This would return

123
1253
123

Here is my code so far, I am stuck from here on

<textarea rows="40" cols="50"></textarea>
<button type="button">Generate</button>

You cannot use just pure HTML, some JavaScript or PHP will have to be used. If all content will keep with the same format that is provided, this simple function will work.

 function findNums() { var value = document.getElementsByTagName("textarea")[0].value; value = value.split("["); value = value[1].split("]"); alert(value[0]); }
 <textarea rows="40" cols="50"></textarea> <button type="button" onClick="findNums()">Generate</button>

HTML is not a programming language. You cannot do that with HTML. Depending on where you get/process the data, you need to use JavaScript on the client side, or a server side language (Python, PHP, JavaScript, Java, ...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM