Reputation: 1309
This is the string:
[randstr: sdfsdfds|dsfsdf sdfds 43rew|fds, 1-1]
This string may occurs in a text. This is my regexp I try:
`\[(randstr|randstrFixed):(\s+)?\|(.+)(\s+)?,(\s+)?[\d]+-[\d]+]`
The main goal to set to the pattern that: sdfsdfds|dsfsdf sdfds 43rew|fds
- here may be any chars but at least one '|' is required. Such requirement because in text may occur another similar string like [randstr: A-Z, 2-4]
More explanation:
https://regex101.com/r/1BNzA4/2/ - here is example text and regexp from @Wiktor Stribiżew
There u can text is changed, now the 'pattern' begins from [->
so in regexp I have to tell it that [->
must mot occur.
Upvotes: 1
Views: 69
Reputation: 626861
You may use
\[randstr(?:Fixed)?:\s*[^][|]*\|[^][]*,\s*\d+-\d+]
See the RE2 regex demo
Details
\[
- a [
charrandstr(?:Fixed)?
- randstr
or randstrFixed
:\s*
- a colon and 0+ whitespaces[^][|]*
- 0+ chars other than [
, ]
and |
\|
- a |
char[^][]*
- 0+ chars other than [
and ]
,\s*
- a comma and 0+ whitespaces\d+-\d+
- 1+ digits, -
, 1+ digits]
- a ]
char.Upvotes: 2