i have the following structure I’d like to parse with RegEx:
[code]<?[Expression]|True>
<?[Expression]|True|False>
<?[Expression]||False>[/code]
I wrote a pattern, which only returns the second and third line.
[code]<\\?\\[(.*)\\]\\|(.*)\\|(.*)?>
$1 returns the Expression
$2 returns the true statement
$2 returns the false statement
[/code]
But I’m not getting the expected results. I’m a little rusty (and was never as good as Kem), so you might need to wait for an expert to come along. Or, you could get the entire second expression, and split on the pipe character.
Dear Jared, thanks for your input. True and False are only variables. So they can be one word ore one ore more sentences! Thats why this solution is not working fine for me.
[quote=339214:@Kem Tekinay]^<\\?\\[([^]\\r\
]+)\\]\\|([^|\\r\
]*)(?:\\|([^>\\r\
]*))?>$[/quote]
Kem, this works pretty well. Thank you so much. There will be some more structures for the conditional sentence function I try to parse. I Think, there will be some more questions within this thread soon
Look, there will be also as structure with conditional angle brackets.
[code]== Class Properties ==
[P] - “Max Mustermann” (Name)
[D] - “1th March 1980” (Date)
[L] - “New York” (Location)
== Sentence ==
[P] was born< [D]>< [L]>.[/code]
The things in angle brackets should only replaced by the properties, if the properties aren’t empty. Otherwise they should replaced by “”.
[P] was born< [D] with text behind.>< [L]>.
And how to handle with text before/behind the variables?!
@Kem,
what it the structure of an if in regex ?
if I use the shortcut in regexrx, I get : code[/code]
but the “if” must not be inside parenthesis in fact ?
it seems to be code[/code] ?
[quote=339235:@Kem Tekinay]
^<\\?\\[?([^]|\\r\
]+)\\]?\\|([^|\\r\
]*)(?:\\|([^>\\r\
]*))?>$
[/quote]
Hi Kem, I found out, that the Pattern is not working correctly.
[code]<?[Expression]|True>
<?[Expression]|True|False>
<?[Expression]||False>[/code]
The first match (Expression) is [b][Expression[/b], but only [b]Expression[/b] should match.