I have a weird string being returned and I need to find a regex to only return the first line, "Next Business Day" or something that I use to replace the everything after the first like that I can replace with an empty string.
I have something like this
$('#my-text').match(/(.|\n)/)
but this is capturing every line. Any advice?
This is the input string:
Next Business Day
- $20.00
Delivery next business day (except holidays). Order must be placed by 12:00 PM ET. Signature required.
$('#my-text').text().match(/(.+)/)
$('#my-text')
returns jQuery object, string methods like match
cannot be used on object. To get innerText of the element use text()
. .+
or .*
. Here .
matches any character that is not newline. Note: To get the matched result use [1]
on the returned array by match.
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.