Rexexp question

[total novice again ;-)]

Hi,

Ok, I’ve figured some of this pattern-matching out (yes, I’m really a
total novice at programming). Consider the following:

====================================
@data.gsub!(/<(text:span
text:style-name=“T10”)>(.?)</text:span>/mois) do
‘{’ + '\bf ’ + $2 + ‘}’
end
@data.gsub!(/<(text:span
text:style-name=“Style2”)>(.
?)</text:span>/mois) do
‘{’ + ‘\it ’ + $2 + ‘}’
end
@data.gsub!(/text:span.*?text:style-name=([\’\"])(.*?)\1(.*?)</text:span>/)
do
tag, text = $2, $3
if inline[tag] then
(inline[tag][0]||’’) + clean_display(text) +
(inline[tag][1]||’’)
else
clean_display(text)
end
end

How can I condense this? I want something that says, eg.

If style-name equals “T10” or “Style2” or “Style3” then do \bf or \it
or \sl respectively. Otherwise, do clean_display (defined elsewhere).
The first line should look like this

==================
@data.gsub!(/<(text:span
text:style-name=(“T10”|“Style2”|“Style3”))>(.*?)</text:span>/mois) do

but how do I modify the

==================
‘{’ + '\bf ’ + $2 + ‘}’

line?

Best
Idris

ishamid wrote:

/ …

==================
‘{’ + '\bf ’ + $2 + ‘}’

line?

It would be helpful if you could providea complete (short) example of
the
data to be processed, plus a statement about the relationship between
the
contents of the data and the desired outcomes. Without necessarily
showing
what you have tried.

IOW show an example of the data, say what outcomes for what data
content.

What you have posted are examples of your regexps and some of the things
that went wrong, but no full examples of data, so it’s hard to see why
it
went wrong.

There are quite a few regular posters here who are pretty good with
regular
expressions. I am sure we can offer some useful hints if we can see the
data plus the desired outcomes.

Hi –

On Sun, 3 Dec 2006, ishamid wrote:

‘{’ + ‘\bf ’ + $2 + ‘}’
(inline[tag][1]||’’)
The first line should look like this

line?

You could perhaps have a hash:

replacements = { ‘“T10”’ => “bf”, ‘“Style2”’ => “it”, ‘“Style3”’ =>
“sl” }

and then replace from the hash:

“{\#{replacements[$1]}#{$2}}”

or something like that.

David

Hi Paul,

On Dec 2, 6:11 pm, Paul L. [email protected] wrote:

ishamid wrote:/ …

==================
‘{’ + '\bf ’ + $2 + ‘}’

There are quite a few regular posters here who are pretty good with regular
expressions. I am sure we can offer some useful hints if we can see the
data plus the desired outcomes.

Ok, I was trying to avoid typing too much :slight_smile: but I will post more
detail tomorrow morning. I am new to ruby, this list, and serious
programming so please bear with me as I get the hang of
appropriate/informative communication on this list.

Thank you, Paul!
Idris