SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Regex help

  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex help

    I need to capture all lines that start C: and end in <br />

    i am struggling to match the end <br />

    i wish to do preg_match_all can any one help?

  2. #2
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you give us an example of a string you want to match and not match?
    What I lack in acuracy I make up for in misteaks

  3. #3
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    ~^C:.*<br/>~
    What I lack in acuracy I make up for in misteaks

  4. #4
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers dude

    the line would look like

    C: server port username password
    C: myserver.no-ip.org 12000 admin admin

    they are an example

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Are you talking break tags or newlnes/carriage returns or all?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lorenw View Post
    Code:
    ~^C:.*<br/>~
    You surely want .*? instead...
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    id like it so that it would just literally match any line that looked like
    Code:
    C: myserver.no-ip.org 12000 admin admin
    and it ignore after the last bit with the <br>

    I found a solution i think now ill post the solution later for any one else looking for something similar

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,078
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    I think you're getting confused between <br /> tags and newlines (\n).

    Something like ^C:.*?$ should do the trick.

    I'm not familiar enough with PHP syntax to write something off the top of my head, but in Ruby it would be:

    Code:
    str = "
    C: myserver.no-ip.org 12000 admin admin
    Some other stuff
    C: myserver.no-ip.org 12000 admin admin
    "
    
    p str.scan(/^C:.*?$/)
    => ["C: myserver.no-ip.org 12000 admin admin", "C: myserver.no-ip.org 12000 admin admin"]
    HTH

  9. #9
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    many thanks i will give this a go

    thank you everyone for your help!


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
  •