Matching exact string with a vertical bar and square brackets
-
I want to match exact strings with a vertical bar and square brackets, but I want to match the shortest possible. Meaning, I want to match the string [aaa|bbb] not anything in this [aaa] | [bbb] or this [aaa] | [aaa|bbb] (in this example, I only want [aaa|bbb], and want the the first [aaa] be ignored (not matched) so I can't use the regex: \[.*?\|(.*?)] It can have non-alphabetical chars, like this [aaa|(ccc)bbb], or be in different languages. What can I do?
-
I want to match exact strings with a vertical bar and square brackets, but I want to match the shortest possible. Meaning, I want to match the string [aaa|bbb] not anything in this [aaa] | [bbb] or this [aaa] | [aaa|bbb] (in this example, I only want [aaa|bbb], and want the the first [aaa] be ignored (not matched) so I can't use the regex: \[.*?\|(.*?)] It can have non-alphabetical chars, like this [aaa|(ccc)bbb], or be in different languages. What can I do?
How about:
\[[^\]]*\|[^\]]*\]
This will match:
- [aaa|bbb]
- [|bbb]
- [aaa|]
- [|]
It will not match:
- [aaa]
- [aaa]|[bbb]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
How about:
\[[^\]]*\|[^\]]*\]
This will match:
- [aaa|bbb]
- [|bbb]
- [aaa|]
- [|]
It will not match:
- [aaa]
- [aaa]|[bbb]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Doesn't seem to work. Using this engine it only matched the first line: a [aaa|bbb] b a [aaa|bbb] b [|bbb] [aaa|] [|] [aaa] [aaa]|[bbb]
-
Doesn't seem to work. Using this engine it only matched the first line: a [aaa|bbb] b a [aaa|bbb] b [|bbb] [aaa|] [|] [aaa] [aaa]|[bbb]
That site finds all five matches for me. Demo[^] Screenshot[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
That site finds all five matches for me. Demo[^] Screenshot[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer