[
と]
の間に文章を出すには、正規表現が必要です。Regexでテキストを検索する
例テキスト:
Hello World - Test[**This is my string**]. Good bye World.
望ましい結果:
**This is my String**
私が出ている正規表現はTest\\[[a-zA-Z].+\\]
であるが、これは全体の**Test[This is my string]**
を返します。
[
と]
の間に文章を出すには、正規表現が必要です。Regexでテキストを検索する
例テキスト:
Hello World - Test[**This is my string**]. Good bye World.
望ましい結果:
**This is my String**
私が出ている正規表現はTest\\[[a-zA-Z].+\\]
であるが、これは全体の**Test[This is my string]**
を返します。
(?<=Test\[)[^\[\]]*(?=\])
あなたがしたいことをする必要があります。
(?<=Test\[) # Assert that "Test[" can be matched before the current position
[^\[\]]* # Match any number of characters except brackets
(?=\]) # Assert that "]" can be matched after the current position
lookaround assertionsで読んでください。 JavaScriptを使用して概念の
\[([^]]+)\]
迅速な証拠:
あなたは関心のテキストにアクセスするためのキャプチャグループを使用することができ
var text = 'Hello World - Test[This is my string]. Good bye World.'
var match = /\[([^\]]+)\]/.exec(text)
if (match) {
console.log(match[1]) // "This is my string"
}
正規表現エンジンあなたがサポートを使用している場合は、両方のlookaheadおよびlookbehind、Timのソリューションがより適切です。
Match m = Regex.Match(@"Hello World - Test[This is my string]. Good bye World.",
@"Test\[([a-zA-Z].+)\]");
Console.WriteLine(m.Groups[1].Value);
ありがとうございます...魅力的です。 – Jakes