For instance, I have a similar block of text like so:> @text = "Lorem ipsum <code>[some code here]</code> dolor sit"What sytax would I use to check if the text is in between the <code> tags? That is: "If @text is in between ''<code>'' and ''</code>'' tags, then do..." Any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MickTaiwan
2007-Aug-15 20:46 UTC
Re: How do you check if text is in between certain <tags>?
Maybe you could look at regular expressions. Mickael. On Aug 15, 10:27 pm, Bob Sanders <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> For instance, I have a similar block of text like so: > > > @text = "Lorem ipsum <code>[some code here]</code> dolor sit" > > What sytax would I use to check if the text is in between the <code> > tags? > > That is: "If @text is in between ''<code>'' and ''</code>'' tags, then > do..." > > Any ideas? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jarod Reid
2007-Aug-15 21:58 UTC
Re: How do you check if text is in between certain <tags>?
Bob Sanders wrote:> For instance, I have a similar block of text like so: > > >> @text = "Lorem ipsum <code>[some code here]</code> dolor sit" >> > > What sytax would I use to check if the text is in between the <code> > tags? > > That is: "If @text is in between ''<code>'' and ''</code>'' tags, then > do..." > > Any ideas? >This regex pattern seems to work /<code>(.*?)\<\/code>/ extracting the string now is a bit more difficult -- jarod --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Aug-16 00:45 UTC
Re: How do you check if text is in between certain <tags>?
If this can / is being done in rjs or javascript, then Prototype has methods that can do this. http://prototypejs.org Jarod Reid wrote:> Bob Sanders wrote: > >> For instance, I have a similar block of text like so: >> >> >> >>> @text = "Lorem ipsum <code>[some code here]</code> dolor sit" >>> >>> >> What sytax would I use to check if the text is in between the <code> >> tags? >> >> That is: "If @text is in between ''<code>'' and ''</code>'' tags, then >> do..." >> >> Any ideas? >> >> > This regex pattern seems to work > > /<code>(.*?)\<\/code>/ > > extracting the string now is a bit more difficult > -- jarod > > > >-- Sincerely, William Pratt http://www.billpratt.net billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Sanders wrote:> For instance, I have a similar block of text like so: > > > @text = "Lorem ipsum <code>[some code here]</code> dolor sit" > > What sytax would I use to check if the text is in between the <code> > tags? > > That is: "If @text is in between ''<code>'' and ''</code>'' tags, then > do..." > > Any ideas?REXML::Document.new(''<xml>'' + my_string + </xml>'') if ''my target'' == REXML::XPath.first(''/xml/code/'').text Test side, you bottle that up in assert_xpath (or assert_hpricot;). Not sure why you need it production-side, and that influences the syntax. If the whole string comes from the user, you need to tolerate faults, and the equivalent Hpricot might work better. And if the string comes from the user, and you don''t want to abuse them and XML at the same time, you could try YAML. -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---