TwelvestoneFront End

Regular Expressions


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Napalm
 
2010-08-10

I have a regular expression to strip out redundant crap that Office generates in its html files, but everything matches tags with quotes in it..... for instance width="20", but how do I match if there's no quotes..... width=20 ?

WIDTH="["]*["]

scudsucker
 
2010-08-10

Untested, as I am a .Net nerd and I am not so sure of the PHP regex, but how about:

width=['"]?['"]*['"]?

Match a string - starting with the word width, - followed by an equals sign, - then zero or one single or double apostrophes, - then any character that is not a single or double apostrophe, - finally zero or one single or double apostrophes.

As (in theory) there will only ever be a number as the width, you could also try:

width=["']?[\d]*['"]?

wowbagger[tip]
 
2010-08-10

Originally posted by: scudsucker As (in theory) there will only ever be a number as the width, you could also try:

width=["']?[\d]*['"]?

You probably meant \d+ (1 or more numbers) but anyway you also have to account for "20%", "20px", "20 " etc. k

~

(?i)width

would match both "WIDTH" and "width" and "Width"

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFront End

Regular Expressions