Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 05-28-2009, 06:03 PM   #1 (permalink)
Mobius's Avatar
 
True Techie

Join Date: Jul 2008

Location: Toronto, Canada

Posts: 147

Mobius is on a distinguished road

Default Regular expression help

Hi guys,

I was wondering if any of you know how I can use regular expression to extract the style attribute out of an html tag

for example:

<p style="blah" class="blah">

I want the result to be style="blah" i tried different ones and ended up with including the last occurence of double quote, so it gave me class="blah" as well.

any help would be great!

Thank you
Mobius
__________________
Project Mobius Web/Graphic Design - [PM me for logo/banner/site designs]
The Web Tech Reviews - [My tech / game review related blog]
Free MMOPRG Games: Secret of Solstice & Fiesta Online
Mobius is offline  
Old 05-28-2009, 06:43 PM   #2 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Regular expression help

Oh how I hate regex. This should do the trick though
style="[\w ]+"
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 05-28-2009, 06:46 PM   #3 (permalink)
Mobius's Avatar
 
True Techie

Join Date: Jul 2008

Location: Toronto, Canada

Posts: 147

Mobius is on a distinguished road

Default Re: Regular expression help

oh man you rock care to explain why it works if you don't mind?

i did some test with RAD software regular expression designer and so far so good!
__________________
Project Mobius Web/Graphic Design - [PM me for logo/banner/site designs]
The Web Tech Reviews - [My tech / game review related blog]
Free MMOPRG Games: Secret of Solstice & Fiesta Online
Mobius is offline  
Old 05-28-2009, 07:35 PM   #4 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Regular expression help

Sure, the \w represents a character that is one of A-Za-z0-9_ the [] creates a character class out of that and space then the + makes it repeat one or more times. In short this makes it look for something that looks like this
style="one or more of the following characters: A-Z a-z 0-9 _"
This is a good site for it Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 05-28-2009, 08:07 PM   #5 (permalink)
Mobius's Avatar
 
True Techie

Join Date: Jul 2008

Location: Toronto, Canada

Posts: 147

Mobius is on a distinguished road

Default Re: Regular expression help

ahh i had this before style=".*" but got more than its suppose to, where as yours just knows to stop at the first closing double quote tag
__________________
Project Mobius Web/Graphic Design - [PM me for logo/banner/site designs]
The Web Tech Reviews - [My tech / game review related blog]
Free MMOPRG Games: Secret of Solstice & Fiesta Online
Mobius is offline  
Old 05-29-2009, 09:10 AM   #6 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Regular expression help

You could use the * to match style="" if you like. Having thought about it you don't really get spaces in attributes but in the style attribute you do get : and ; which my fist expression will not catch.
Try style="[^"]*" (if you want style="" to be caught) or style="[^"]+" (if you don't) instead. These ones will catch spaces but they will also catch more than just alphanumeric words as well.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 07-24-2009, 09:05 AM   #7 (permalink)
 
Newb Techie

Join Date: Jul 2009

Posts: 1

komandin is on a distinguished road

Default Re: Regular expression help

Regex

style="[^"]+"

Last edited by kmote; 07-24-2009 at 09:07 AM. Reason: No links to personal websites
komandin is offline  
 
Closed Thread

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help, Windows will not boot in regular mode Ghaleon Windows Operating Systems and Software 3 03-24-2009 08:42 PM
Burning Regular and DL DVDs bitsetting akasixcon Windows Operating Systems and Software 6 02-22-2009 02:13 PM
Installing Ubuntu. 95BlackGA Linux, BSD, other *nixes & Open Source Software 1 10-16-2008 09:44 PM
Asus p5q pro v. asus p5q (regular) Jtumble2 Building, Buying, or Upgrading High Performance PC Systems 21 10-01-2008 02:14 AM
Plays DVD's But doesn't read regular CD's? More Boost Everything Laptops 2 02-01-2008 06:43 PM