Reputation: 643
I'd love someone to help me with this regex. I'd like to be able to isolate the regex to detect characters in the string below between the * |
and | *
:
Hello this is "*|first_name||default_value|*"
I appreciate your help.
Upvotes: 0
Views: 48
Reputation: 110685
Nothing fancy:
'Hello this is "*|first_name||default_value|*"'[/\*\|(.+)?\|\*/,1]
#=> "first_name||default_value"
Upvotes: 0
Reputation: 41838
Use this:
if subject =~ /\*\|\K.*?(?=\|\*)/
match = $&
See demo.
\*\|
matches *|
\K
tells the engine to drop what was matched so far from the match it will report.*?
lazily matches everything up to...(?=\|\*)
can assert that what follows is |*
Reference
Upvotes: 4