For a silly bbcode parser I wanted to add two definitions into one, my original definition was this for preg_replace:
'#\[s\](.*?)\[/s\]#si', '<strike>\\1</strike>'
And this works, I wished for the user to be able to use either [s]
or [strike]
to initiate text in that format, so I naturally added something like this thinking it would work:
'#\[(s|strike)\](.*?)\[/(s|strike)\]#si', '<strike>\\1</strike>'
Unfortunately that fails, instead of what you would expect, both [s]
and [strike]
(used properly) make: and s
(my markdown is correct to show its real looking result, it shows s or strike regardless of what is inside it)strike
Why does it replace the inner text with the tag name instead? Is my adding parentheses around the s|strike the problem? I am probably doing this all wrong..
[syntax=cpp][/syntax]
like bbcode regex to pass source code to geshi, so it is quite fun to use this instead. :) – Hurried[u][strike][b]underbold[/u] boldandstrike[/b][u]onlyunderline&strike[/strike][/u]should be clear
and it worked. I do not use more complex stuff so I don't think it is a problem. – Hurried<>
out). – Slumgullion(.)\1
into his backtracking NFA code ingrep
: the language described by(.)\1
is not REGULAR in that st00pid textbook REGULARity definition that nobody uses and which does not apply to modern regexes. – Russonegrep
can match(.)\1
, which is not REGULAR. See here, here, and here — &c&c&c! – Russon\((?:[^()]*+|(?0))*\)
is a beautiful regex. – Russonfor/given
loop. How much more readable could you get? :) – Russongrep
style line-noise atrocities as (insert your favorite very-high-level programming language) has with machine language. A modern regex can be very close to a BNF grammar spec, for example. There is absolutely no reason to accept these/☕✷⅋⋙$⚣™‹ª∞¶⌘̤℈⁑‽#♬˘$π❧/
tortured abominations from anybody in this day and age. Modern regexes are a whole new world, if not numinous then at least luminous. :) – Russon