# Rexexp question

**URL:** <https://www.ruby-forum.com/t/rexexp-question/78030>\
**Category:** Ruby\
**Created:** [December 2, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/rexexp-question/78030 "2006-12-02T23:10:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishamid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ad7895/32.png) [@ishamid](https://www.ruby-forum.com/u/ishamid)\
**Post date:** [December 2, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/rexexp-question/78030/1 "2006-12-02T23:10:37Z")

</div>

[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

---

<div class="post-metadata">

**Author:** ![ishamid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ad7895/32.png) [@ishamid](https://www.ruby-forum.com/u/ishamid)\
**Post date:** [December 3, 2006, 2:15am UTC](https://www.ruby-forum.com/t/rexexp-question/78030/2 "2006-12-03T02:15:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ishamid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ad7895/32.png) [@ishamid](https://www.ruby-forum.com/u/ishamid)\
**Post date:** [December 3, 2006, 2:31am UTC](https://www.ruby-forum.com/t/rexexp-question/78030/3 "2006-12-03T02:31:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ishamid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ad7895/32.png) [@ishamid](https://www.ruby-forum.com/u/ishamid)\
**Post date:** [December 3, 2006, 4:15am UTC](https://www.ruby-forum.com/t/rexexp-question/78030/4 "2006-12-03T04:15:49Z")

</div>

Hi Paul,

On Dec 2, 6:11 pm, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂 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
