Find the range bounded by ()
from the string passed by the argument str
and return the string for that part.
()
returns empty characters if the contents are empty.()
returns the contents of the first parenthesis found if there are multiple ()
(Quickest match) ()
is not found.If ()
is empty, I want to return an empty character, but it says null.
Could you please let me know?
function extractStr(str){
varret=/\(.+?)\)/.exec(str);
return ret?ret[1]: null;
}
If the contents of ( ) are empty, I want to return empty characters, but it says null.
The regular expression is \(.+?)\)
, and (.+?)
is specified in parentheses. +?
is one or more characters long, so if () is empty, does not apply and fails.The regular expression must be \(.*?)\)
using *?
for zero or more characters if you want it to succeed even if it is empty.
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
581 PHP ssh2_scp_send fails to send files as intended
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.