perlre is your friend here :)
For your first marker, you probably want to use a character class. So you might have something like: He[012].
For the middle part of your expression, it depends what you expect it to contain. If you're confident that it will only be alphanumeric characters and whitespace, then you could use ([\w\s]+)
\w denotes an alphanumeric character, \s denotes any whitespace character. These are wrapped in a character class by using the square brackets "[]", and the + quantifier is used, meaning "match one or more". The whole lot is wrapped in parentheses because you want to "capture" the string.
The end part of the expression is easy, as you said it will always end with "~~"
So, putting it all together you get (untested):
m/He[012]([\w\s]+)~~/
The captured string will be available in the $1 variable afterwards.
One point to note: If you have several such strings in a single line of data, then only the last first match will be returned. You could capture all matches into a list by using the 'g' modifier, like so:
my @strings = m/He[012]([/w/s]+)~~/g;
Hope this helps,
Darren :)
In reply to Re: Get chars between 2 markers using regular expressions
by McDarren
in thread Get chars between 2 markers using regular expressions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |