Solved

trying to get text between certain words

Posted on 2013-02-06
6
226 Views
Last Modified: 2013-02-08
The text below looks messy but thats how we get files sent to us sometimes.
I want to retrieve all text between "JOIN" and "="

sample text....

SELECT
*
  FROM mytable ppst
       LEFT OUTER JOIN mytable2 pps
                ON ppst.id = pps.id
       LEFT OUTER JOIN mytable3 ps                ON ps.id = pps.p_id
       LEFT OUTER JOIN test p                                  ON p.id = pps.prod_id                        

                                          -- make join inner when data in product
       LEFT OUTER JOIN product p2                            ON p2.id = ppst.to_product_id                                

                              -- make join inner when data in product
       LEFT OUTER JOIN filer f                                  

ON f.id = ppst.did
-- WHERE ps.published_by IS NOT NULL


so - if the regular expression works the it should return
##############################################
mytable2 pps
                ON ppst.id
mytable3 ps                ON ps.id
test p                                  ON p.id
product p2                            ON p2.id
filer f                                  

ON f.id
##############################################
ideally I would like ..
mytable2 pps ON ppst.id
mytable3 ps ON ps.id
test p ON p.id
product p2 ON p2.id
filer f ON f.id

I'm trying this expression but its not working

if record =~/join(.|\n\r\f)*=/i
            puts record
0
Comment
Question by:PHIL Sawyer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 38861370
Match the text you want with this pattern (using ignore case and singleline modifiers):
(?<=join).*?(?==)
then to remove the surplus spaces substitute pattern
\s{2,}
with a single space.

If you actually have the comments (starting with --) in the text, then you may need to remove those prior to the above.

I'm not a Ruby programmer, by the way; my specialty is regular expressions. Note also there is a Regular Expressions topic with other experts who contribute...
0
 

Author Comment

by:PHIL Sawyer
ID: 38863144
if record =~/(?<=join).*?(?==)/i then

the above misses the 2 lines
 LEFT OUTER JOIN mytable2 pps
                ON ppst.id = pps.id

and it returns the whole line and not the text between join and =

Regards
0
 

Author Comment

by:PHIL Sawyer
ID: 38863468
just to correct my above posting ...
it does capture text between "join and =" and only returns data between those variables but does not return the first 2 lines - must be to do with = is on the next line

Regards
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 38865622
Yes, you'll need the singleline modifier. Like this, I believe:

 if record =~/(?<=join).*?(?==)/is then
0
 

Author Comment

by:PHIL Sawyer
ID: 38867959
Thanks
0
 

Author Closing Comment

by:PHIL Sawyer
ID: 38867960
Thanks
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question