Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 30th, 2008, 09:01 PM
DrWorm's Avatar
DrWorm DrWorm is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Location: Queensland, Australia
Posts: 827 DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 18 h 34 sec
Reputation Power: 140
Find inner HTML

I've created a simple template system with language translation.

All the template files should contain either HTML tags or <? ?> for PHP code. There should be no text in the templates as the text should all be stored in PHP variables.

I need a regular expression that I can use to search through all my templates and make sure it doesn't contain any text between tags.

To be thorough I would also like it to locate text used in attributes such as alt or title, but that's not so important.

I don't seem to be able to get my head around how to search for words that do not begin with < or end with >
__________________
Ooh, they have the Internet on computers now!

Reply With Quote
  #2  
Old December 1st, 2008, 03:31 PM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
So your templates are all just tags (or should be at least). Then this could do the trick:

Code:
^(\s*<[^>]*>)+\s*$

Reply With Quote
  #3  
Old December 1st, 2008, 05:01 PM
DrWorm's Avatar
DrWorm DrWorm is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Location: Queensland, Australia
Posts: 827 DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 18 h 34 sec
Reputation Power: 140
Quote:
Originally Posted by prometheuzz
So your templates are all just tags (or should be at least). Then this could do the trick:

Code:
^(\s*<[^>]*>)+\s*$

That matches the tags. I need the opposite of that so I can use it to find files that contain text between tags.

Reply With Quote
  #4  
Old December 2nd, 2008, 01:07 AM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
Quote:
Originally Posted by DrWorm
That matches the tags. I need the opposite of that so I can use it to find files that contain text between tags.


Well, the negation can be handled in the programming language you're writing this in.
But, this will match text outside of a tag:

Code:
[^<>]+(?=[^>]*(?:<|$))

Reply With Quote
  #5  
Old December 2nd, 2008, 09:34 PM
DrWorm's Avatar
DrWorm DrWorm is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Location: Queensland, Australia
Posts: 827 DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 18 h 34 sec
Reputation Power: 140
Quote:
Originally Posted by prometheuzz
Well, the negation can be handled in the programming language you're writing this in.

I should have stressed I'm not using this in a programming language. I'm using it in a "Find" dialog in NetBeans.
Quote:
But, this will match text outside of a tag:

Code:
[^<>]+(?=[^>]*(?:<|$))

It does except it also matches spaces. It's really only [a-zA-Z] that needs to be found. I feel like I've already trouble you too much, but if you're compelled to figure out another regex I would truely appreciate it. In the mean time this expression will give me something to examine and learn from.

Reply With Quote
  #6  
Old December 3rd, 2008, 12:59 AM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
Quote:
Originally Posted by DrWorm
I should have stressed I'm not using this in a programming language. I'm using it in a "Find" dialog in NetBeans.

It does except it also matches spaces. It's really only [a-zA-Z] that needs to be found. I feel like I've already trouble you too much, but if you're compelled to figure out another regex I would truely appreciate it. In the mean time this expression will give me something to examine and learn from.


I think that after a short explanation of the regex, you will be able to change it (slightly) so that it suits your needs.

Code:
[^<>]+      // one or more characters of any type except '<' and '>'
(?=         // start positive look ahead
  [^>]*     //   zero or more characters of any type except '>'
  (?:<|$)   //   either '<' or the end of the string
)           // stop positive look ahead


Feel free to post back if you have further questions.

Reply With Quote
  #7  
Old December 3rd, 2008, 05:13 PM
DrWorm's Avatar
DrWorm DrWorm is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Location: Queensland, Australia
Posts: 827 DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 18 h 34 sec
Reputation Power: 140
Thanks very much for the explaination. I'm not familiar with "look aheads" so that'll give me something to research on.

The regex is no longer urgent so i'm happy to take the time to figure it out and learn from it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Find inner HTML

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap