Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
最初の [ と最後の ] の間にコンテンツを取得する必要がある同じ文字が他にある場合でも、シンボル [ と ] の間にコンテンツを取得する必要があります。正規表現を使用するjqueryで。事前に感謝
jQuery は必要ありません。標準の Javascript を使用してください。
var extract = str.match(/\[(.*)\]/).pop();
区切り文字が { と } の場合は、次のように変更します
var extract = str.match(/{(.*)}/).pop();
どうですか
yourStringVariable.match(/\[(.*)\]/)[1]