greg
3/14/2007 3:10:00 AM
/ \*'''
([A-Z1-9]+) # acronym
'',\s*
(?:
\[\[ ([\w\s]+) \]\] # acronym definition with matching optional
parens
|
([\w\s]+) # acronym definition without parens
)
/x
?: means don't capture what is in the parentheses
This also assumes that there are either two brackets or zero (not one)
Note that you will have to check to see if the match is in $2 or $3
The most important thing about regular expressions is to be as
specific as possible with what you specify, and think about all the
possibilities of what will be matched and what will not be matched
To match 'Acronym Definition' I am using [\w\s]+
There is a good chance that this is overly broad for your application
On Mar 13, 3:15 pm, "eddieroger" <eddiero...@gmail.com> wrote:
> I'm trying to write a regular expression for Ruby and running into
> roadblocks. I'm not new to the concept of a regex, and have written
> many before, but I'm new to implementation in Ruby and working with a
> particularly pesky regex.
>
> The string I need to match is:
> *'''ABC'', [[Acronym Definition]]
>
> The only parts I want to change are the ABC and "Acronym Definition."
> So, the asterisk, quotes and brackets should be there, but - to make
> it harder - the brackets are optional.
>
> Thanks for the help!
> Eddie