dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: patterns

  1. #1
    Join Date
    Dec 2011
    Posts
    8

    patterns

    hello,

    im trying to create a pattern that will split my text on spaces, but not when there is <img infront.

    this is becaus i want to split my text on spaces and place them between <span></span>, but when i add <img src=""> it will go like <span><img</span><span>src=""></span>.. wont work

    my experience with regular expressions is not so great, but im trying my best

  2. #2
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74
    On parsing HTML with regular expressions, I would like to refer you to what I think must be the best answer ever given to a question on Stack Overflow:
    http://stackoverflow.com/questions/1...732454#1732454
    For a discussion of that post, and why it's a bad idea, see: http://www.codinghorror.com/blog/200...hulhu-way.html

    More constructively, as to how to solve this problem - do you need to do it live - i.e. via some sort of Ajax method - or can you possibly do it via a server-side script? I don't know of any HTML parsers written in JavaScript. There's one for Python that I've been using called Beautiful Soup which works well, but server-side Python isn't something that most web hosting packages support...

  3. #3
    Join Date
    Dec 2011
    Posts
    8
    im not trying to parse, im trying to split and then with a forloop im adding the span classes.. does that make any difference?

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Presumably you want to split on any spaces that aren't within <tags>. If so try splitting on this pattern:

    /\x20+(?![^<]*>)/

  5. #5
    Join Date
    Dec 2011
    Posts
    8
    /\x20+(?![^<]*>)/ works thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles