SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expressions are hard :( please help

    I have a specific point in a string I want a page break, I need some help with the regexp for it

    the string where I want to insert a break is this

    Code:
    ....ending of paragraph. Some Text: More text.....
    What would be the proper regexp to put a break before Some Text?

    From what I know of them I got [ ].+: which I know is wrong cause it takes out everything after the first word in the paragraph to the colon

    and searching for Some Text isn't an option cause it is different on each entry, though im fairly sure there is 2 words in front of the colon in each

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You being familiar with the text samples, what do you think about searching for the period, followed by between 5-20 of any character, followed by colon? Do you think that might be more reliable than searching for two words, and considering stuff like punctuation?

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right that would make more sense.

    So... I want to insert a <br /> after the period(.) that comes before the colon: in the string, with any number in between.

    something like
    \\.[ ]+:

    perhaps?

    Is what is in between the brackets that gets replaced?
    I am still a little confused with how this works

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo preg_replace('#\.([^:]{5,20}:)#''.<br>$1'$text1); 
    The $1 will be expanded to contain the text matched by the part of the regex in the parenthesis.

    [^:]{5,20} means between 5 and 20 of any character except colon.

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome

    It works,Thanks


Bookmarks

Posting Permissions

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